gpNamespace.TyNetManager = cc.Class.extend({
    self: null,
    isGameStart: false,

    outTime: null,
    lastOutTime: null,
    inTime: null,
    lastInTime: null,

    gonggaolanLayer: null,
    labaLayer: null,
    gonggaoStr: [],
    cddGonggaoLayer:null,
    sjpdLayer:null,

    registerLayer: null,
    logLayer: null,
    qpsLayer: null,
    topLayer: null,
    gpMiddleLayer:null,
    bottomLayer: null,

    userInfoLayer: null,
    propInit: false,
    bindLayer: null,
    changeLayer: null,
    changeInfoLayer: null,
    innerUserPropLayer: null,

    signLayer: null,
    signInit: false,
    
    helpLayer:null,
    mailLayer: null,
    gonggaoLayer: null,
    gonggaoMoreLayer: null,

    missionLayer: null,
    gameLayer: null,
    ddzGameLayer: null,
    friendLayer: null,

    rankLayer: null,
    qszbRankLayer: null,

    eggLayer: null,
    eggName: null,
    eggPic: null,
    eggInfo: null,
    eggNameLayer: null,

    scLayer: null,
    isInit1: false,
    isInit2: false,
    isInit3: false,
    isInit4: false,
    scAdded: false,

    buyGoldLayer: null,
    buyPropLayer: null,
    buyVoucherLayer: null,
    userPropLayer: null,
    gamePropLayer: null,

    gameEndLayer: null,
    ruchangLayer: null,
    pochanLayer: null,

    ddzMiddleLayer: null,
    mjMiddleLayer: null,

    innerMissionRewardTimes: 0,

    goodPriceType: null,
    goodPrice: null,

    isUseProp: false,

    added: false,

    payGoodID: null,
    payGoodMoney: null,
    payGoodName: null,
    payType: null,


    currentNetManager:null,
    ctor: function () {
        this.init();
    },

    init: function () {
        this.self = this;

        //cc.eventManager.addCustomListener(NetEvent.GS_Register, this.onRegister.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_Login, this.onLogin.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_Account, this.onAccount.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_LogonFinish, this.onLogonFinish.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_ChangeInfo, this.onChangeInfo.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_MarketItem, this.onMarketItem.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_MarketBuyCz, this.onMarketBuyCz.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_MarketBuyJb, this.onMarketBuyJb.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_MarketBuyDj, this.onMarketBuyDj.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_MarketBuySw, this.onMarketBuySw.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GoodInfo, this.onGoodInfo.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_PayInfo, this.onPayInfo.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_PayResult, this.onPayResult.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_MyProp, this.onMyProp.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_UserProp, this.onUseProp.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_BeforeUserProp, this.onBeforeUseProp.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_UseLaba, this.onUseLaba.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_PokeCount, this.onPokeCount.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_UsePropResult, this.onUsePropResult.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_Sign, this.onMySign.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_SetSign, this.onSetSign.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GetSign, this.onGetSign.bind(this));
        
	    cc.eventManager.addCustomListener(NetEvent.GS_MailList, this.onGetMail.bind(this));
	    cc.eventManager.addCustomListener(NetEvent.GS_MailEdit, this.onMailEdit.bind(this));
	    cc.eventManager.addCustomListener(NetEvent.GS_MailInfo, this.onMailInfo.bind(this));
	    cc.eventManager.addCustomListener(NetEvent.GS_SendMail, this.onSendMail.bind(this));
	    cc.eventManager.addCustomListener(NetEvent.GS_Rank, this.onRank.bind(this));
	        
        
        cc.eventManager.addCustomListener(NetEvent.GS_Mission, this.onMission.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_MissionReward, this.onMissionReward.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GameMissionReward, this.onGameMissionReward.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_InnerMission, this.onInnerMission.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_Friend, this.onFriend.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_EditFriend, this.onEditFriend.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_FriendVerify, this.onFriendVerify.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_FriendResponse, this.onFriendResponse.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_SearchFriend, this.onSearchFriend.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_Talk, this.onGetTalk.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_HistoryTalk, this.onGetHistoryTalk.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_HistoryLaba, this.onGetHistoryLaba.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_Egg, this.onEgg.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GoldEgg, this.onGoldEgg.bind(this));//wn新曾
        cc.eventManager.addCustomListener(NetEvent.GS_CanEgg, this.onCanEgg.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_EggNameList, this.onEggNameList.bind(this));
        
//        cc.eventManager.addCustomListener(NetEvent.GS_QQLibao, this.onQQLibao.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_Pochan, this.onPochan.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_Ruchang, this.onRuchang.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_UserTalk, this.onUserTalk.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_GameNotice, this.onGameNotice.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_RestTime, this.onRestTime.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GameKick, this.onGameKick.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GameCheat, this.onGameCheat.bind(this));

        cc.eventManager.addCustomListener(NetEvent.GS_Gonggao, this.onGonggao.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GetQQ, this.onGetQQ.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GetWX, this.onGetWX.bind(this));
        cc.eventManager.addCustomListener(NetEvent.GS_GetVIPDays, this.onGetVIPDays.bind(this));

        cc.eventManager.addCustomListener(GameFrameEvent.GAME_FRAME_MESSAGE, this.onFrameMessage.bind(this));
        

        cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, this.onHide.bind(this));
        cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, this.onShow.bind(this));
        
        cc.eventManager.addCustomListener(NetEvent.GS_InnerUserInfo, this.onGameUserInfo.bind(this));

        //cc.eventManager.addListener({
        //    event: cc.EventListener.KEYBOARD,
        //    onKeyReleased: function (keyCode, event) {
        //        if (keyCode == cc.KEY.back) {
        //            gpNamespace.showDialog("结束");
        //
        //            cc.director.end();
        //        }
        //        else if (keyCode == cc.KEY.menu) {
        //            gpNamespace.showDialog("菜单键");
        //        }
        //    }
        //}, this);
        
        ccs.armatureDataManager.addArmatureFileInfo(
        		gpNamespace.vipAnimationRes.vipexpression_png,
        		gpNamespace.vipAnimationRes.vipexpression_plist,
        		gpNamespace.vipAnimationRes.vipexpression_json);
    },
    
    onGameUserInfo: function (event) {
    	cc.log("onInnerUserInfo");

    	var innerInfo = event.getUserData();

	cc.log("result:" + innerInfo.result);
	cc.log("loseCount:" + innerInfo.loseCount);
	cc.log("pingCount:" + innerInfo.pingCount);
	cc.log("winCount:" + innerInfo.winCount);
	cc.log("itemCount:" + innerInfo.itemCount);
	for (var a = 0; a < innerInfo.items.length; a++) {
	    cc.log("goodID:" + innerInfo.items[a][0]);
	    cc.log("goodIconID:" + innerInfo.items[a][1]);
	    cc.log("goodCount:" + innerInfo.items[a][2]);
	    cc.log("goodPrice:" + innerInfo.items[a][3]);
	    cc.log("goodType:" + innerInfo.items[a][4]);
	    cc.log("--------------------------");
	}

    	gpNamespace.GameUserInfo.RESULT = innerInfo.result;
    	gpNamespace.GameUserInfo.LOSECOUNT = innerInfo.loseCount;
    	gpNamespace.GameUserInfo.DRAWCOUNT = innerInfo.pingCount;
    	gpNamespace.GameUserInfo.WINCOUNT = innerInfo.winCount;
    	gpNamespace.GameUserInfo.ITEMCOUNT = innerInfo.itemCount;
    	gpNamespace.GameUserInfo.ITEMS = [];
    	for (var a = 0; a < gpNamespace.GameUserInfo.ITEMCOUNT; a++) {
    		gpNamespace.GameUserInfo.ITEMS[a] = [];
    		gpNamespace.GameUserInfo.ITEMS[a][0] = innerInfo.items[a][0];
    		gpNamespace.GameUserInfo.ITEMS[a][1] = innerInfo.items[a][1];
    		gpNamespace.GameUserInfo.ITEMS[a][2] = innerInfo.items[a][2];
    		gpNamespace.GameUserInfo.ITEMS[a][3] = innerInfo.items[a][3];
    		gpNamespace.GameUserInfo.ITEMS[a][4] = innerInfo.items[a][4];
    	}

    	if (gpNamespace.GameUserInfo.RESULT == 1)
    		this.innerUserInfoLayer.setGameUserInfo();

    	tyNamespace.removeWaitLayer();
    },

    onFrameMessage: function (event) {
    	var message = event.getUserData();

    	cc.log("onFrameMessage:" + message.id);

    	switch (message.id) {
    	//断线重连提示
    	case NetConstant.SUB_GS_RECONNECTNOTIFY:
    	{
    		this.onReconnectNotify(message.data);
    		break;
    	}
    	//断线重连
    	case NetConstant.SUB_GS_RECONNECT:
    	{
    		this.onReconnect(message.data);
    		break;
    	}
    	}
    },

    onReconnectNotify: function (byData) {
    	var roomType = byData.readByte();
    	gpNamespace.roomType = roomType;
    	gpNamespace.subRoom = byData.readByte(); //1-6
    	gpNamespace.biXia = byData.readInt();
    	gpNamespace.difen = byData.readInt();
    	gpNamespace.roomLimitScore = byData.readInt();
    	gpNamespace.chouShui = byData.readInt();
    	gpNamespace.currentCount = byData.readInt();
    	
    	cc.log("gpNamespace.subRoom:" + gpNamespace.subRoom);
    	cc.log("gpNamespace.difen:" + gpNamespace.difen);

    	var gameScene = null;

    	gameScene = new gpNamespace.GpMainScene();
    	currentNetManager = gpNamespace.NetManager.getInstance();
    	
    		currentNetManager.isReconnnect=true;
    	
    	if (gpNamespace.subRoom > 7)
    		currentNetManager.isMatch = true;

    	if (gpNamespace.subRoom > 5)
    		currentNetManager.useGold = false;

    	currentNetManager.addMyListeners();
    	cc.director.runScene(gameScene);
    },

    //重新连接
    onReconnect: function (data) {
    	
    	currentNetManager = gpNamespace.NetManager.getInstance();
    	currentNetManager.isReconnnect = true;
    	cc.log("TY——NetManager断线重连收到消息+++++++++++++++++++++++++");
    	var reconnect = new gpNamespace.reconnect();

    	reconnect.readBody(data);
    	currentNetManager.onReconnect(reconnect);
    },

    setGonggaolan: function (layer) {
        this.gonggaolanLayer = layer;
    },

    setLabaLayer: function (layer) {
        this.labaLayer = layer;
    },

    setRegisterLayer: function (layer) {
        this.registerLayer = layer;
    },

    setLogLayer: function (layer) {
        this.logLayer = layer;
    },

    setQpsLayer: function (layer) {
        this.qpsLayer = layer;
    },

    setTopLayer: function (layer) {
        this.topLayer = layer;
    },

    setgpMiddleLayer: function (layer) {
    	this.gpMiddleLayer = layer;
    },

    setBottomLayer: function (layer) {
        this.bottomLayer = layer;
    },

    setUserInfoLayer: function (layer) {
        this.userInfoLayer = layer;
    },

    setBindLayer: function (layer) {
        this.bindLayer = layer;
    },

    setChangeLayer: function (layer) {
        this.changeLayer = layer;
    },

    setChangeInfoLayer: function (layer) {
        this.changeInfoLayer = layer;
    },

    setVIPLayer: function (layer) {
        this.vipLayer = layer;
    },

    setInnerUserPropLayer: function (layer) {
        this.innerUserPropLayer = layer;
    },

    setSignLayer: function (layer) {
        this.signLayer = layer;
    },

    setHelpLayer:function(layer){
    	this.helpLayer = layer;
    },
    setMailLayer: function (layer) {
        this.mailLayer = layer;
    },

    setGonggaoLayer: function (layer) {
        this.gonggaoLayer = layer;
    },

    setCddGonggaoLayer: function (layer) {
    	this.cddGonggaoLayer = layer;
    },
    setSjpdLayer: function (layer) {
    	this.sjpdLayer = layer;
    },

    setGonggaoMoreLayer: function (layer) {
        this.gonggaoMoreLayer = layer;
    },

    setMissionLayer: function (layer) {
        this.missionLayer = layer;
    },

    setGameLayer: function (layer) {
        this.gameLayer = layer;
    },

    setDdzGameLayer: function (layer) {
        this.ddzGameLayer = layer;
    },

    setFriendLayer: function (layer) {
        this.friendLayer = layer;
    },

    setRankLayer: function (layer) {
        this.rankLayer = layer;
    },

    setQszbRankLayer: function (layer) {
        this.qszbRankLayer = layer;
    },

    setKxdzsRankLayer: function (layer) {
        this.kxdzsRankLayer = layer;
    },

    setEggLayer: function (layer) {
        this.eggLayer = layer;
    },

    setZajindanRankLayer: function (layer) {
        this.eggNameLayer = layer;
    },

    setSCLayer: function (layer) {
        this.scLayer = layer;
    },

    setBuyGoldLayer: function (layer) {
        this.buyGoldLayer = layer;
    },

    setBuyPropLayer: function (layer) {
        this.buyPropLayer = layer;
    },

    setBuyVoucherLayer: function (layer) {
        this.buyVoucherLayer = layer;
    },

    setGameEndLayer: function (layer) {
        this.gameEndLayer = layer;
    },
    
    setGamePropLayer: function (layer) {
    	this.gamePropLayer = layer;
    },

    setRuchangLayer: function (layer) {
        this.ruchangLayer = layer;
    },

    setPochanLayer: function (layer) {
        this.pochanLayer = layer;
    },

    setInnerUserInfoLayer: function (layer) {
        this.innerUserInfoLayer = layer;
    },

    setUserPropLayer: function (layer) {
        this.userPropLayer = layer;
    },

    setDdzMiddleLayer: function (layer) {
        this.ddzMiddleLayer = layer;
    },

    setMjMiddleLayer: function (layer) {
        this.mjMiddleLayer = layer;
    },

    setPayType: function (type) {
        this.payType = type;
    },

    initMarket: function () {
        this.isInit1 = false;
        this.isInit2 = false;
        this.isInit3 = false;
        this.isInit4 = false;
    },

    onLogin: function (event, userInfoCache) {
        cc.log("onLogin");

        var login = event.getUserData();

		cc.log(login.islog);
		cc.log("pochanCount:" + login.pochanCount);
		cc.log("win:" + login.shengCount);
		cc.log("lose:" + login.shuCount);
		cc.log("ping:" + login.pingCount);
		cc.log("diamond:" + login.diamond);
		cc.log("voucher:" + login.voucher);
		cc.log("gold:" + login.gold);
		cc.log("grade:" + login.grade);
		cc.log("headImageID:" + login.headImageID);
		cc.log("isFeng:" + login.isFeng);
		cc.log("isBuyOne:" + login.isBuyOne);
		cc.log("isChange:" + login.isChange);
		cc.log("isBuyNew:" + login.isBuyNew);
		cc.log("isReconnect:" + login.isReconnect);
		cc.log("isSign:" + login.isSign);
		cc.log("isKickEgg:" + login.isKickEgg);
		cc.log("isVip:" + login.isVip);
		cc.log("isInEgg:" + login.isInEgg);
		cc.log("userID:" + login.userID);
		cc.log("userIDShow:" + login.userIDShow);
		cc.log("gender:" + login.gender);
		cc.log("headImagePath:" + login.headImagePath);
		cc.log("nickName:" + login.nickName);
		cc.log("vipDays:" + login.vipDays);
		
		gpNamespace.LoginInfo.ISLOG = login.isLog;
		gpNamespace.LoginInfo.USERID = login.userID;
		gpNamespace.LoginInfo.NICKNAME = login.nickName;
		gpNamespace.LoginInfo.HEADIMAGEID = login.headImageID;
		gpNamespace.LoginInfo.VIP = login.isVip;
		gpNamespace.LoginInfo.VIPDAYS = login.vipDays;
		gpNamespace.LoginInfo.GOLD = login.gold;
		gpNamespace.LoginInfo.DIAMOND = login.diamond;
		gpNamespace.LoginInfo.VOUCHER = login.voucher;
		gpNamespace.LoginInfo.SEX = login.gender;
		gpNamespace.LoginInfo.ISCHANGEVOICE = login.isChange;
		gpNamespace.LoginInfo.ISBUYONE = login.isBuyOne;
		gpNamespace.LoginInfo.WINCOUNT = login.winCount;
		gpNamespace.LoginInfo.LOSECOUNT = login.loseCount;
		gpNamespace.LoginInfo.DRAWCOUNT = login.drawCount;
		gpNamespace.LoginInfo.POCHANCOUNT = login.pochanCount;
		gpNamespace.LoginInfo.ISBUYNEW = login.isBuyNew;
		gpNamespace.LoginInfo.ISBUYONE = login.isBuyOne;
		gpNamespace.LoginInfo.ISINEGG = login.isInEgg;
		gpNamespace.LoginInfo.ISKICKEGG = login.isKickEgg;
		gpNamespace.LoginInfo.ISSIGN = login.isSign;

//        var runningScene = cc.director.getRunningScene();
//        var juhua = runningScene.getChildByName(tyNamespace.Juhua);
//        juhua && juhua.removeFromParent(true);tyNamespace.addWaitLayer();
//    	  tyNamespace.removeWaitLayer();

        //封时候需要调试
        if (login.isFeng) {
            var runningScene = cc.director.getRunningScene();
            var tyModelLayer = new tyNamespace.ModelLayer();
            runningScene.addChild(tyModelLayer, 10);

            var pochanLayer = new gpNamespace.CannotLogLayer(); //弹出框
            pochanLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(pochanLayer);

            pochanLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

            return;
        }
     
		userInfo = login;

        //cc.sys.localStorage.setItem(gpNamespace.USER_ID_BYTE, login.userID.join(","));

        this.showLogin(login);
    },

    //登录后，显示主界面顶部信息
    showLogin: function (login) {
        if (!login.isReconnect) {
            var runningScene = cc.director.getRunningScene();
            var juhua = runningScene.getChildByName(gpNamespace.Juhua);
            juhua && juhua.removeFromParent(true);
        }
//        	cc.log("用户名："+login.nickName);
            this.topLayer.setUserNameLabel(login.nickName);
//            this.topLayer.setUserHeadImage(login.headImageID);
//            cc.log("頭像："+login.headImageID);
            
//            this.topLayer.removeChildByTag(101);
//            this.topLayer.removeChildByTag(102);
//            this.topLayer.removeChildByTag(103);
            this.topLayer.setUserGold(login.gold);
            this.topLayer.setUserDiamond(login.diamond);
            this.topLayer.setUserVoucher(login.voucher);
            if(login.isVip){
            	this.topLayer.showVip();
            	cc.log("是vip");
            }
            this.bottomLayer.setEggTips();

            xinyou.netManager.getRank(1);//获取排行榜
//          xinyou.netManager.getFriend();//获取好友
            xinyou.netManager.getMail(1);//获取邮件列表，用于主页提示
            xinyou.netManager.getHistoryTalk();//获取历史信息
            xinyou.netManager.getHistroyLaba();
        //
        //cc.log("QQ:"+xinyou.netManager.getQQ());
        //xinyou.netManager.getQQ();
        //
        //xinyou.netManager.getRestTime(1);

            //this.resetLocalInfo();
          
          if(!userInfo.isReconnect){
        	  var runningScene = cc.director.getRunningScene();
        	  var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
        	  var modelLayer = new tyNamespace.ModelLayer(70);
        	  modelLayer.setTouchArea(cc.size(1138, 576), cc.p(72, 70));
        	  modelLayerCancelable.addChild(modelLayer);
        	  runningScene.addChild(modelLayerCancelable, 10);
        	  var gonggaoLayer = new gpNamespace.GonggaoLayer();
        	  gonggaoLayer.attr({
        		  //左上角坐标
        		  x: 0,
        		  y: 0
        	  });
        	  modelLayer.addChild(gonggaoLayer);
        	  cc.log("####userInfo.isKickEgg:"+userInfo.isKickEgg);
        	  if(!userInfo.isKickEgg){
        		  cc.log("##userInfo.isKickEgg:"+userInfo.isKickEgg);
        		  var modelLayerCancelable2 = new tyNamespace.ModelLayerCancelable();
        		  var modelLayer2 = new tyNamespace.ModelLayer(70);
        		  modelLayer2.setTouchArea(cc.size(1140, 560), cc.p(66, 94));
        		  modelLayerCancelable2.addChild(modelLayer2);
        		  runningScene.addChild(modelLayerCancelable2, 10);
        		  var zjdLayer = new gpNamespace.ZjdLayer();//砸金蛋
        		  zjdLayer.attr({
        			  //左上角坐标
        			  x: 0,
        			  y: 0
        		  });
        		  modelLayer2.addChild(zjdLayer);
        	  }

        	  if(!userInfo.isSign){
        		  var modelLayerCancelable3 = new tyNamespace.ModelLayerCancelable();
        		  var modelLayer3 = new tyNamespace.ModelLayer(70);
        		  modelLayer3.setTouchArea(cc.size(1140, 480), cc.p(62, 87));
        		  modelLayerCancelable3.addChild(modelLayer3);
        		  runningScene.addChild(modelLayerCancelable3, 10);
        		  var qqlbLayer = new gpNamespace.QqlbLayer();//qq礼包
        		  qqlbLayer.attr({
        			  //左上角坐标
        			  x: 0,
        			  y: 0
        		  });
        		  modelLayer3.addChild(qqlbLayer);
        	  }
          }
            
    },

    resetEGGorONE: function () {
        var newArmature = this.qpsLayer.getChildByName("newArmature");
        var eggArmature = this.qpsLayer.getChildByName("eggArmature");
        if (cc.sys.isObjectValid(newArmature)) {
            newArmature.removeFromParent(true);
        }
        if (cc.sys.isObjectValid(eggArmature)) {
            eggArmature.removeFromParent(true);
        }
        if (cc.sys.isObjectValid(this.qpsLayer.xinshouDlbMenu)) {
            this.qpsLayer.xinshouDlbMenu.setPosition(this.qpsLayer.itemPosition[0].x + 120 / 2, this.qpsLayer.itemPosition[0].y + 120 / 2);
            this.qpsLayer.xinshouDlbMenu.setVisible(false);
        }

        if (cc.sys.isObjectValid(this.qpsLayer.jindanDlbMenu)) {
            this.qpsLayer.jindanDlbMenu.setPosition(this.qpsLayer.itemPosition[1].x + 120 / 2, this.qpsLayer.itemPosition[1].y + 120 / 2);
            this.qpsLayer.jindanDlbMenu.setVisible(false);
        }
        if (cc.sys.isObjectValid(this.qpsLayer.blackEgg)) {
            this.qpsLayer.blackEgg.setPosition(this.qpsLayer.itemPosition[1].x + 120 / 2, this.qpsLayer.itemPosition[1].y + 120 / 2);
            this.qpsLayer.blackEgg.setAnchorPoint(0.5, 0.5);
            this.qpsLayer.blackEgg.setVisible(false);
        }
    },

    setEggorONE: function () {
        if (!userInfo.isBuyNew) {
            if (cc.sys.isObjectValid(this.qpsLayer.xinshouDlbMenu))
                this.qpsLayer.xinshouDlbMenu.setVisible(false);
            var armature = new ccs.Armature("zjm_xsdlb_01c");
            armature.getAnimation().playWithIndex(0);
            armature.getAnimation().setSpeedScale(1);
            armature.setScale(1);
            armature.setAnchorPoint(0.5, 0.5);
            armature.setPosition(this.qpsLayer.armaturePosition[0].x, this.qpsLayer.armaturePosition[0].y);
            this.qpsLayer.addChild(armature);
            armature.setName("newArmature");
            armature.getAnimation().setMovementEventCallFunc(this.xinshouDlbCallbackFunction, this);
        }
        else {
            if (cc.sys.isObjectValid(this.qpsLayer)) {
                var newArmature = this.qpsLayer.getChildByName("newArmature");
                if (newArmature) {
                    newArmature.removeFromParent(true);
                }
                this.qpsLayer.xinshouDlbMenu.setVisible(false);

                this.qpsLayer.jindanDlbMenu.setPosition(this.qpsLayer.itemPosition[0].x + 120 / 2, this.qpsLayer.itemPosition[0].y + 120 / 2);
                this.qpsLayer.blackEgg.setPosition(this.qpsLayer.itemPosition[0].x + 120 / 2, this.qpsLayer.itemPosition[0].y + 120 / 2);
                this.qpsLayer.blackEgg.setAnchorPoint(0.5, 0.5);
            }
        }

        if (userInfo.isInEgg) {
            if (!userInfo.isKickEgg) {
                if (cc.sys.isObjectValid(this.qpsLayer.jindanDlbMenu))
                    this.qpsLayer.jindanDlbMenu.setVisible(false);
                if (cc.sys.isObjectValid(this.qpsLayer.blackEgg))
                    this.qpsLayer.blackEgg.setVisible(false);
                var armature = new ccs.Armature("yx_xsdlb_01a");
                armature.getAnimation().playWithIndex(0);
                armature.getAnimation().setSpeedScale(1);
                armature.setScale(1);
                armature.setAnchorPoint(0.5, 0.5);

                if (!userInfo.isBuyNew) {
                    armature.setPosition(this.qpsLayer.armaturePosition[1].x, this.qpsLayer.armaturePosition[1].y);
                }
                else {
                    armature.setPosition(this.qpsLayer.armaturePosition[0].x, this.qpsLayer.armaturePosition[0].y);
                }

                this.qpsLayer.addChild(armature);
                armature.setName("eggArmature");
                armature.getAnimation().setMovementEventCallFunc(this.jindanDlbCallbackFunction, this);
            }
            else {
                if (cc.sys.isObjectValid(this.qpsLayer)) {
                    var eggArmatrue = this.qpsLayer.getChildByName("eggArmature");
                    if (eggArmatrue) {
                        eggArmatrue.removeFromParent(true);
                    }
                    this.qpsLayer.jindanDlbMenu.setVisible(false);
                    this.qpsLayer.blackEgg.setVisible(true);
                }
            }
        }
    },

    addSign: function (login) {
        if (!login.isSign) {
            var runningScene = cc.director.getRunningScene();
            var tyModelLayer = new gpNamespace.TyModelLayer();
            runningScene.addChild(tyModelLayer, 10);

            var tySignLayer = new gpNamespace.TySignLayer();
            tySignLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tySignLayer);

            tySignLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

            xinyou.netManager.getSign();
        }
    },

    addGonggao: function () {
        var runningScene = cc.director.getRunningScene();
        var tyModelLayer = new tyNamespace.TyModelLayer();
        runningScene.addChild(tyModelLayer, 10);

        var tyHdLayer = new gpNamespace.TyHdLayer();
        tyHdLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(tyHdLayer);

        tyHdLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

        this.gonggaoLayer.scheduleOnce(function () {
            xinyou.netManager.getGonggao(1);
        }, 0.3);
    },

    resetLocalInfo: function () {
        gpNamespace.TyFriendData = [];
    },

    jindanDlbCallbackFunction: function (armature, movementType, movementID) {
        if (movementType == ccs.MovementEventType.complete) {
            //armature.removeFromParent(true);
            this.qpsLayer.jindanDlbMenu.setVisible(true);
            this.qpsLayer.blackEgg.setVisible(false);
        }
    },

    xinshouDlbCallbackFunction: function (armature, movementType, movementID) {
        if (movementType == ccs.MovementEventType.complete) {
            //armature.removeFromParent(true);
            this.qpsLayer.xinshouDlbMenu.setVisible(true);
        }
    },

    onAccount: function (event) {
        cc.log("onAccount");

        var account = event.getUserData();

        cc.log("account:" + account.accountType);

        switch (account.accountType) {
            case 1: //绑定成功
                userInfo.gold = userInfo.gold + 1000;
                //cc.log("account.accountType---1");
                if (cc.sys.isObjectValid(this.userInfoLayer)) {
                    this.userInfoLayer.registerMenu.setVisible(false);
                    this.userInfoLayer.wanchengSprite.setVisible(true);
                    this.userInfoLayer.wanchengModelSprite.setVisible(true);
                    this.userInfoLayer.gantanhaoBackground.setVisible(false);
                    this.userInfoLayer.setGold(userInfo.gold);
                }

                if (cc.sys.isObjectValid(this.topLayer)) {
                    this.topLayer.gantanhaoBackground.setVisible(false);
                    this.topLayer.setUserGold(userInfo.gold);
                }

                if (cc.sys.isObjectValid(this.bindLayer)) {
                    this.bindLayer.jump("注册成功！");
                    this.bindLayer.getParent().getParent().removeFromParent(true);
                }

                //参赛券表现--------------------------------------------------------------
                var runningScene = cc.director.getRunningScene();
                var jumpLayer = new cc.Layer();
                runningScene.addChild(jumpLayer, 10);

                var gold = new cc.Sprite("#mj_ty_70.png");
                gold.attr({
                    x: 540,
                    y: 500
                });
                jumpLayer.addChild(gold);
                gold.setScale(0.6);

                //乘号
                var plusName = "#zuos_030u.png";
                var plus = new cc.Sprite(plusName);
                plus.attr({
                    x: 610,
                    y: 500
                });
                jumpLayer.addChild(plus);

                //数量
                var count = 1000;
                for (var i = 0; i < count.toString().length; i++) {
                    var str = parseInt(count.toString().substr(i, 1)) + 20;
                    var spritName = "#zuos_0" + str + "u.png";
                    var countCell = new cc.Sprite(spritName);
                    countCell.attr({
                        x: 630 + 24 * i,
                        y: 500
                    });
                    jumpLayer.addChild(countCell);
                }

                var runningScene = cc.director.getRunningScene();
                var runningArmature = new ccs.Armature("coins");
                runningArmature.getAnimation().playWithIndex(0);
                runningArmature.getAnimation().setSpeedScale(1);
                runningArmature.setScale(1);
                runningArmature.setAnchorPoint(0.5, 0.5);
                runningArmature.setPosition(560, 580);
                runningScene.addChild(runningArmature, 10);
                runningArmature.getAnimation().setMovementEventCallFunc(this.callBackRemove, runningScene);

                jumpLayer.runAction(cc.sequence(cc.spawn(cc.moveBy(1.5, 0, 60), cc.fadeOut(1.5)), cc.callFunc(function () {
                    jumpLayer.removeFromParent(true);
                })));
                //-------------------------------------------------------------------------

                break;

            case 2: //用户名重复
                //cc.log("account.accountType---2");
                if (cc.sys.isObjectValid(this.userInfoLayer)) {
                    this.userInfoLayer.registerMenu.setVisible(true);
                    this.userInfoLayer.wanchengSprite.setVisible(false);
                    this.userInfoLayer.wanchengModelSprite.setVisible(false);
                }

                var lastName = cc.sys.localStorage.getItem(gpNamespace.USER_LASTNAME);
                var lastPwd = cc.sys.localStorage.getItem(gpNamespace.USER_LASTPASSWORD);
                if (tyNamespace.checkStore(lastName) && tyNamespace.checkStore(lastPwd)) {
                    cc.sys.localStorage.setItem(gpNamespace.USER_NAME, lastName);
                    cc.sys.localStorage.setItem(gpNamespace.USER_PASSWORD, lastPwd);
                }
                else {
                    cc.sys.localStorage.removeItem(gpNamespace.USER_NAME);
                    cc.sys.localStorage.removeItem(gpNamespace.USER_PASSWORD);
                }

                if (cc.sys.isObjectValid(this.bindLayer)) {
                    this.bindLayer.jump("注册失败：用户名重复！");
                }

                break;

            case 3: //修改密码成功
                //cc.log("account.accountType---3");
                var password = cc.sys.localStorage.getItem(gpNamespace.USER_PASSWORDTEMP);
                cc.sys.localStorage.setItem(gpNamespace.USER_PASSWORD, password);
                cc.sys.localStorage.removeItem(gpNamespace.USER_PASSWORDTEMP);

                if (cc.sys.isObjectValid(this.changeLayer)) {
                    this.changeLayer.jump("修改成功！");
                    this.changeLayer.getParent().getParent().removeFromParent(true);
                }

                break;

            case 4: //账号和密码不匹配
                //cc.log("account.accountType---4");
                cc.sys.localStorage.removeItem(gpNamespace.USER_NEW_PASSWORD);
                cc.sys.localStorage.removeItem(gpNamespace.USER_PASSWORDTEMP);

                if (cc.sys.isObjectValid(this.changeLayer)) {
                    this.changeLayer.jump("修改失败：账号或旧密码不正确！");
                }

                break;

            case 5: //修改信息成功
            	cc.log("##########性别修改成功！");

                /*if (cc.sys.isObjectValid(this.changeLayer)) {
                    this.changeInfoLayer.nameField.setVisible(false);
                    this.changeInfoLayer.nickNameLabel.setVisible(true);
                    this.changeInfoLayer.manMenu.setVisible(false);
                    this.changeInfoLayer.womanMenu.setVisible(false);
                    this.changeInfoLayer.red1.setVisible(false);
                    this.changeInfoLayer.red2.setVisible(false);
                }

                if (cc.sys.isObjectValid(this.userInfoLayer)) {
                    this.userInfoLayer.changeInfoMenu.setVisible(false);
                    this.userInfoLayer.infoMenu.setVisible(true);
                    this.userInfoLayer.setUserHead(gpNamespace.chooseHeadID);
                    this.userInfoLayer.userNameLabel.setString(gpNamespace.changeName);
                }

                if (cc.sys.isObjectValid(this.topLayer)) {
                    this.topLayer.setUserHeadImage(gpNamespace.chooseHeadID);
                    this.topLayer.userNameLabel.setString(gpNamespace.changeName);
                }

                if (gpNamespace.changeSex == "男") {
                    if (cc.sys.isObjectValid(this.changeLayer)) {
                        this.changeInfoLayer.manSprite.setVisible(true);
                        this.changeInfoLayer.womanSprite.setVisible(false);
                    }
                    if (cc.sys.isObjectValid(this.userInfoLayer)) {
                        this.userInfoLayer.sexBackground1.setVisible(true);
                        this.userInfoLayer.sexBackground2.setVisible(false);
                    }
                    if (cc.sys.isObjectValid(this.topLayer)) {
                        this.topLayer.sexBackground1.setVisible(true);
                        this.topLayer.sexBackground2.setVisible(false);
                    }
                }
                if (gpNamespace.changeSex == "女") {
                    if (cc.sys.isObjectValid(this.changeInfoLayer)) {
                        this.changeInfoLayer.manSprite.setVisible(false);
                        this.changeInfoLayer.womanSprite.setVisible(true);
                    }
                    if (cc.sys.isObjectValid(this.userInfoLayer)) {
                        this.userInfoLayer.sexBackground1.setVisible(false);
                        this.userInfoLayer.sexBackground2.setVisible(true);
                    }
                    if (cc.sys.isObjectValid(this.topLayer)) {
                        this.topLayer.sexBackground1.setVisible(false);
                        this.topLayer.sexBackground2.setVisible(true);
                    }
                }

                userInfo.isChange = true;
                userInfo.headImageID = gpNamespace.chooseHeadID;
                userInfo.nickName = gpNamespace.changeName;
                userInfo.gender = gpNamespace.changeSex;

                this.changeInfoLayer.getParent().getParent().removeFromParent(false);
*/
                break;

            case 6: //昵称已被使用
                //cc.log("account.accountType---6");

                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("昵称已被使用！");
                runningScene.addChild(tyJumpLayerWithText, 10);

                break;

            case 7: //昵称和性别只能修改一次
                //cc.log("account.accountType---6");

                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("昵称和性别只能修改一次！");
                runningScene.addChild(tyJumpLayerWithText, 10);

                break;

            case 8: //邮箱重复
                //cc.log("account.accountType---2");
                if (cc.sys.isObjectValid(this.userInfoLayer)) {
                    this.userInfoLayer.registerMenu.setVisible(true);
                    this.userInfoLayer.wanchengSprite.setVisible(false);
                    this.userInfoLayer.wanchengModelSprite.setVisible(false);
                }

                var lastName = cc.sys.localStorage.getItem(gpNamespace.USER_LASTNAME);
                var lastPwd = cc.sys.localStorage.getItem(gpNamespace.USER_LASTPASSWORD);
                if (tyNamespace.checkStore(lastName) && tyNamespace.checkStore(lastPwd)) {
                    cc.sys.localStorage.setItem(gpNamespace.USER_NAME, lastName);
                    cc.sys.localStorage.setItem(gpNamespace.USER_PASSWORD, lastPwd);
                }
                else {
                    cc.sys.localStorage.removeItem(gpNamespace.USER_NAME);
                    cc.sys.localStorage.removeItem(gpNamespace.USER_PASSWORD);
                }

                if (cc.sys.isObjectValid(this.bindLayer)) {
                    this.bindLayer.jump("注册失败：邮箱已被注册！");
                }

                break;
        }

        //if (account.accountType) {
        //    this.userInfoLayer.registMenu.setVisible(false);
        //    this.userInfoLayer.wanchengSprite.setVisible(true);
        //}
        //else {
        //    cc.sys.localStorage.removeItem(gpNamespace.USER_NAME);
        //    cc.sys.localStorage.removeItem(gpNamespace.USER_PASSWORD);
        //}
    },

    onLogonFinish: function () {
        cc.log("onlogonFinish");

        gpNamespace.gameInited = true;
        cc.eventManager.removeCustomListeners(NetEvent.GS_LogonFinish);
    },

    onChangeInfo: function (event) {
        cc.log("onChangeInfo");

        var change = event.getUserData();

        //cc.log("change:" + change.changeType);
    },

    onMarketItem: function (event) {
        cc.log("marketItem");

        var marketItem = event.getUserData();

        switch (marketItem.showType) {
            case 1:
                this.onQuickCharge(event);
                break;

            case 2:
                this.onGoldExchange(event);
                break;

            case 3:
                this.onPropExchange(event);
                break;

            case 4:
                this.onPhysicalExchange(event);
                break;
        }
    },

    onQuickCharge: function (event) {
        cc.log("quickCharge");

        var quickCharge = event.getUserData();

//        if (!this.isInit1 && this.scLayer)
          if (this.scLayer){
        	  this.scLayer.setQuicklyChargeInfo(quickCharge);
//        	  console.log("!!!!!!!!!!!!!!!!"+quickCharge.itemCount);
          }
    },

    onGoldExchange: function (event) {
        cc.log("onExchange");

        var goldExchange = event.getUserData();

        if (this.scLayer){
        	this.scLayer.setGoldDhInfo(goldExchange);
//        	console.log("!!!!!!!!!!!!!!!!"+goldExchange.itemCount);
        }
    },

    onPropExchange: function (event) {
        cc.log("onPropExchange");

        var propExchange = event.getUserData();

        if (this.scLayer){
        	this.scLayer.setgameDjInfo(propExchange);
//        	console.log("!!!!!!!!!!!!!!!!"+propExchange.itemCount);
        	}
    },
    //商城实物奖品数据
    onPhysicalExchange: function (event) {
        cc.log("onPhysicalExchange");

        var physicalExchange = event.getUserData();
        
//      if (!this.isInit4 && this.scLayer)
//      cc.log(" if (!this.isInit4 && this.scLayer)");
        if (this.scLayer){
        	this.scLayer.setRealJpInfo(physicalExchange);
        }
//            this.addPhysicalExchangeContent(physicalExchange);
    },

    getIconName: function (iconID, offset) {
        var realName = (iconID - offset).toString();
        while (realName.length < 3) {
            realName = "0" + realName;
        }
        return realName;
    },

    addQuickChargeContent: function (data) {
        this.isInit1 = true;
        var scLayer = this.scLayer;

        var itemArray = [];
        for (var a = 0; a < data.itemCount; a++) {
            itemArray[a] = new cc.Sprite(gpNamespace.sc.Sc_kuaisuchongzhiBackground);

            var goodIcon;
            if (data.goods[a][1] >= 2000 && data.goods[a][1] < 2012) {
                //实物图标
                var goodIconID = data.goods[a][1];
                var goodIconName = "#zjm_scq_" + this.getIconName(goodIconID, 1999) + "u.png";
                goodIcon = new cc.Sprite(goodIconName);
                goodIcon.attr({
                    x: 66,
                    y: 77
                });
                itemArray[a].addChild(goodIcon);
            }
            if (data.goods[a][1] == 0) {
                //实物图标
                var goodID = data.goods[a][0];
                goodIcon = new LoadHead(goodID);
                goodIcon.loadGood();
                goodIcon.attr({
                    x: 66,
                    y: 77
                });
                itemArray[a].addChild(goodIcon);
            }

            //商品数量
            var goodQuantity = data.goods[a][3];
            var goodQuantityNew = gpNamespace.InsertCharIntoString(goodQuantity.toString(), ",", 3);
            for (var i = 0; i < goodQuantityNew.length; i++) {
                var spritName;
                if (goodQuantityNew.substr(i, 1) == ",")
                    spritName = "#zjm_sc_110u.png";
                else {
                    var str = goodQuantityNew.substr(i, 1);
                    spritName = "#zjm_sc_10" + str + "u.png";
                }
                var countCell = new cc.Sprite(spritName);
                countCell.attr({
                    x: 128 + 20 * i,
                    y: 86,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(countCell);
            }

            //价格数量
            var priceQuantity = data.goods[a][2];
            for (var i = priceQuantity.toString().length, j = 0; i > 0; i--, j++) {
                var str = priceQuantity.toString().substr(i - 1, 1);
                var spritName = "#zjm_sc_12" + str + "u.png";
                var countCell = new cc.Sprite(spritName);
                countCell.attr({
                    x: 384 - 16 * j,
                    y: 92,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(countCell);
            }

            //价格类型
            var yuan = new cc.Sprite("#zjm_sc_130u.png");
            yuan.attr({
                x: 403,
                y: 89,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(yuan);

            //说明
            var goodType = data.goods[a][5];
            var info = new cc.LabelTTF("¥" + priceQuantity + "元 = " + goodQuantity + "金币", "Arial", 28);
            if (goodType == gpNamespace.ScGoodType.Diamond)
                info = new cc.LabelTTF("¥" + priceQuantity + "元 = " + goodQuantity + "钻石", "Arial", 28);
            info.attr({
                x: 135,
                y: 32,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(info);

            //购买
            var buyItem = new cc.MenuItemImage(gpNamespace.sc.Sc_buyModel, gpNamespace.sc.Sc_buyModel, this.buy1CallbackFunction, this);
            buyItem.attr({
                x: 455 / 2,
                y: 149 / 2
            });
            buyItem.setUserData([data.goods[a][0]]);
            var buyMenu = new gpNamespace.TyMenu(buyItem);
            buyMenu.attr({
                x: 0,
                y: 0
            });
            itemArray[a].addChild(buyMenu);
            buyMenu.setTouchArea(scLayer.scrollview1.touchArea);
        }

        scLayer.scrollview1.setMyContainer(itemArray, 167, 2);
    },

    buy1CallbackFunction: function (sender) {
        cc.log("购买1");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        var goodID = data[0];

        this.payGoodID = goodID;

        xinyou.netManager.getPayInfo(goodID);
    },

    onPayInfo: function (event) {
        cc.log("onPayInfo");

        var pay = event.getUserData();

        //cc.log("money:" + pay.money);
        //cc.log("goodName:" + pay.goodName);

        var runningScene = cc.director.getRunningScene();
        var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        var tyModelLayer = new gpNamespace.TyModelLayer();
        tyModelLayer.setTouchArea(cc.size(602, 447), cc.p(339, 137));
        tyModelLayer1.addChild(tyModelLayer);
        runningScene.addChild(tyModelLayer1, 10);

        this.payGoodMoney = pay.money;
        this.payGoodName = pay.goodName;

        var payLayer = new gpNamespace.PayLayer(this.payGoodID, pay.goodName, pay.money);
        payLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(payLayer);

        payLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
    },

    onPayResult: function (event) {
        cc.log("onPayResult");

        var pay = event.getUserData();

        //cc.log("payGoodID:" + pay.payGoodID);
        //cc.log("result:" + pay.result);
        //cc.log("itemCount:" + pay.itemCount);
        //for (var a = 0; a < pay.itemCount; a++) {
        //    cc.log("goodID:" + pay.goods[a][0]);
        //    cc.log("goodCount:" + pay.goods[a][1]);
        //    cc.log("----------------");
        //}

        //gpNamespace.showDialog("result:" + pay.result + "itemCount:" + pay.itemCount);

        if (pay.result == 1) {
            gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinEffect, false);

            if (pay.payGoodID == 54) {//一元礼包
                userInfo.isBuyOne = true;
            }

            if (pay.payGoodID == 55) {//新手礼包
                userInfo.isBuyNew = true;

                //if (cc.sys.isObjectValid(this.qpsLayer)) {
                //    var newArmature = this.qpsLayer.getChildByName("newArmature");
                //    if (newArmature) {
                //        newArmature.removeFromParent(true);
                //    }
                //    this.qpsLayer.xinshouDlbMenu.setVisible(false);
                //}

                //xinyou.netManager.useProp(56, -1);
            }

            for (var a = 0; a < pay.itemCount; a++) {
                switch (pay.goods[a][0]) {
                    case 1://金币
                        if (cc.sys.isObjectValid(this.topLayer)) {
                            userInfo.gold = userInfo.gold + pay.goods[a][1];
                            this.topLayer.setUserGold(userInfo.gold);
                        }

                        break;

                    case 2://钻石
                        if (cc.sys.isObjectValid(this.topLayer)) {
                            userInfo.diamond = userInfo.diamond + pay.goods[a][1];
                            this.topLayer.setUserDiamond(userInfo.diamond);
                        }

                        break;

                    case 3://兑换券
                        if (cc.sys.isObjectValid(this.topLayer)) {
                            userInfo.voucher = userInfo.voucher + pay.goods[a][1];
                            this.topLayer.setUserDui(userInfo.voucher);
                        }

                        break;
                    case 35://vip周卡
                        userInfo.isVip = true;
                        this.topLayer && this.topLayer.showVip();
                        cc.log("userInfo.isVip!!!"+userInfo.isVip);
                        break;
                    case 39://喇叭
                        cc.log("喇叭*"+pay.goods[a][1]);
                        break;
                }
            }
            tyNamespace.tipsJumper(1,"充值成功！");
        }
    },

    onMarketBuyCz: function (event) {
        cc.log("marketBuyCz");

        var buyRMB = event.getUserData();

        //cc.log("result:" + buyRMB.result);
        //cc.log("billNumber:" + buyRMB.billNumber);

        switch (buyRMB.result) {
            case 1 : //生成订单成功
                if (cc.sys.os == cc.sys.OS_ANDROID)
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "pay", "(Ljava/lang/String;ILjava/lang/String;I)V", this.payGoodName, this.payGoodMoney * 100, buyRMB.billNumber, this.payType);

                break;

            case 2: //已买过1元礼包
                gpNamespace.showDialog("您已购买过1元礼包");

                break;

            case 3: //已买过新手礼包
                gpNamespace.showDialog("您已购买过新手礼包");

                break;
        }
    },

    addGoldExchangeContent: function (data) {
        this.isInit2 = true;
        var scLayer = this.scLayer;

        var itemArray = [];
        for (var a = 0; a < data.itemCount; a++) {
            itemArray[a] = new cc.Sprite(gpNamespace.sc.Sc_youxibiduihuanBackground);

            var goodIcon;
            if (data.goods[a][1] >= 3000 && data.goods[a][1] < 3004) {
                //实物图标
                var goodIconID = data.goods[a][1];
                var goodIconName = "#zjm_scg_" + this.getIconName(goodIconID, 2999) + "u.png";
                goodIcon = new cc.Sprite(goodIconName);
                goodIcon.attr({
                    x: 66,
                    y: 77
                });
                itemArray[a].addChild(goodIcon);
            }
            if (data.goods[a][1] == 0) {
                //实物图标
                var goodID = data.goods[a][0];
                goodIcon = new LoadHead(goodID);
                goodIcon.loadGood();
                goodIcon.attr({
                    x: 66,
                    y: 77
                });
                itemArray[a].addChild(goodIcon);
            }

            //商品数量
            var goodQuantity = data.goods[a][3];
            var goodQuantityNew = gpNamespace.InsertCharIntoString(goodQuantity.toString(), ",", 3);
            for (var i = 0; i < goodQuantityNew.length; i++) {
                var spritName;
                if (goodQuantityNew.substr(i, 1) == ",")
                    spritName = "#zjm_sc_110u.png";
                else {
                    var str = goodQuantityNew.substr(i, 1);
                    spritName = "#zjm_sc_10" + str + "u.png";
                }
                var countCell = new cc.Sprite(spritName);
                countCell.attr({
                    x: 128 + 20 * i,
                    y: 86,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(countCell);
            }

            //价格数量
            var priceQuantity = data.goods[a][2];
            for (var i = priceQuantity.toString().length, j = 0; i > 0; i--, j++) {
                var str = priceQuantity.toString().substr(i - 1, 1);
                var spritName = "#zjm_sc_12" + str + "u.png";
                var countCell = new cc.Sprite(spritName);
                countCell.attr({
                    x: 334 - 16 * j,
                    y: 92,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(countCell);
            }

            //价格类型
            //var yuan = new cc.Sprite("#zjm_sc_130u.png");
            var priceType = data.goods[a][6];
            var spriteName = "#zjm_sc_131u.png";
            if (priceType == gpNamespace.ScGoodType.ExchangeVoucher)
                spriteName = "#zjm_sc_132u.png";
            var yuan = new cc.Sprite(spriteName);
            yuan.attr({
                x: 353,
                y: 89,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(yuan);

            //图标
            var priceType = data.goods[a][6];
            if (priceType == gpNamespace.ScGoodType.ExchangeVoucher) {
                var spriteName = "#zjm_sc_153u.png";
                var icon = new cc.Sprite(spriteName);
                icon.attr({
                    x: 383,
                    y: 80,
                    anchorX: 0,
                    anchorY: 0
                });
                icon.setScale(0.4);
                itemArray[a].addChild(icon);
            } else {
                var spriteName = "#zjm_sc_154u.png";
                var icon = new cc.Sprite(spriteName);
                icon.attr({
                    x: 383,
                    y: 85,
                    anchorX: 0,
                    anchorY: 0
                });
                icon.setScale(0.4);
                itemArray[a].addChild(icon);
            }

            //说明
            var priceType = data.goods[a][6];
            var info = new cc.LabelTTF("¥" + priceQuantity + "钻 = " + goodQuantity + "金币", "Arial", 28);
            if (priceType == gpNamespace.ScGoodType.ExchangeVoucher)
                info = new cc.LabelTTF("¥" + priceQuantity + "券 = " + goodQuantity + "金币", "Arial", 28);
            info.attr({
                x: 135,
                y: 32,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(info);

            //购买
            var buyItem = new cc.MenuItemImage(gpNamespace.sc.Sc_buyModel, gpNamespace.sc.Sc_buyModel, this.buy2CallbackFunction, this);
            buyItem.attr({
                x: 455 / 2,
                y: 149 / 2
            });
            buyItem.setUserData([data.goods[a][0], data.goods[a][2], data.goods[a][6]]);
            var buyMenu = new gpNamespace.TyMenu(buyItem);
            buyMenu.attr({
                x: 0,
                y: 0
            });
            itemArray[a].addChild(buyMenu);
            buyMenu.setTouchArea(scLayer.scrollview2.touchArea);
        }

        scLayer.scrollview2.setMyContainer(itemArray, 167, 2);
    },

    buy2CallbackFunction: function (sender) {
        cc.log("购买2");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        //cc.log("data:" + data);

        var goodID = data[0];
        var priceQuantity = data[1];
        var priceType = data[2];

        var runningScene = cc.director.getRunningScene();
        var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        var tyModelLayer = new gpNamespace.TyModelLayer();
        tyModelLayer.setTouchArea(cc.size(605, 451), cc.p(325, 161));
        tyModelLayer1.addChild(tyModelLayer);
        runningScene.addChild(tyModelLayer1, 10);

        var scBuyGoldLayer = new gpNamespace.ScBuyGoldLayer();
        scBuyGoldLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(scBuyGoldLayer);
        scBuyGoldLayer.setGoodID(goodID);
        scBuyGoldLayer.setPriceQuantity(priceQuantity);
        scBuyGoldLayer.setPriceType(priceType);

        scBuyGoldLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

        xinyou.netManager.getGoodInfo(goodID);

        this.setBuyGoldLayer(scBuyGoldLayer);
    },

    onMarketBuyJb: function (event) {
        cc.log("marketBuyJb");

        var marketBuyJb = event.getUserData();
//        this.topLayer.removeChildByTag(101);
//        this.topLayer.removeChildByTag(102);
//        this.topLayer.removeChildByTag(103);
        this.topLayer && this.topLayer.setUserGold(marketBuyJb.gold);
        this.topLayer && this.topLayer.setUserDiamond(marketBuyJb.diamond);
        this.topLayer && this.topLayer.setUserVoucher(marketBuyJb.voucher);

        //cc.sys.localStorage.setItem(gpNamespace.GOLD, marketBuyJb.gold);
        //cc.sys.localStorage.setItem(gpNamespace.DIAMOND, marketBuyJb.diamond);
        //cc.sys.localStorage.setItem(gpNamespace.VOUCHER, marketBuyJb.voucher);

        userInfo.gold = marketBuyJb.gold;
        userInfo.diamond = marketBuyJb.diamond;
        userInfo.voucher = marketBuyJb.voucher;

        switch (marketBuyJb.result) {
            case 0 : //成功
                cc.log("购买金币成功");

//                gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinEffect, false);

                break;

            case 1: //钻石不足
            	cc.log("钻石不足");
//                var runningScene = cc.director.getRunningScene();
//                var tyModelLayer1 = new gpNamespace.TyModelLayer1();
//                var tyModelLayer = new gpNamespace.TyModelLayer();
//                tyModelLayer.setTouchArea(cc.size(576, 315), cc.p(352, 203));
//                tyModelLayer1.addChild(tyModelLayer);
//                runningScene.addChild(tyModelLayer1, 10);
//
//                var scDiamondJumpLayer = new gpNamespace.ScDiamondJumpLayer();
//                scDiamondJumpLayer.attr({
//                    x: 0,
//                    y: cc.winSize.height
//                });
//                tyModelLayer.addChild(scDiamondJumpLayer);
//
//                scDiamondJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;

            case 2: //兑换券不足
            	cc.log("兑换券不足");
//                var runningScene = cc.director.getRunningScene();
//                var tyModelLayer1 = new gpNamespace.TyModelLayer1();
//                var tyModelLayer = new gpNamespace.TyModelLayer();
//                tyModelLayer.setTouchArea(cc.size(576, 315), cc.p(352, 203));
//                tyModelLayer1.addChild(tyModelLayer);
//                runningScene.addChild(tyModelLayer1, 10);
//
//                var scVoucherJumpLayer = new gpNamespace.ScVoucherJumpLayer();
//                scVoucherJumpLayer.attr({
//                    x: 0,
//                    y: cc.winSize.height
//                });
//                tyModelLayer.addChild(scVoucherJumpLayer);
//
//                scVoucherJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;

            case 3: //金币不足
            	cc.log("金币不足");
//                var runningScene = cc.director.getRunningScene();
//                var tyModelLayer1 = new gpNamespace.TyModelLayer1();
//                var tyModelLayer = new gpNamespace.TyModelLayer();
//                tyModelLayer.setTouchArea(cc.size(576, 315), cc.p(352, 203));
//                tyModelLayer1.addChild(tyModelLayer);
//                runningScene.addChild(tyModelLayer1, 10);
//
//                var scGoldDiamondJumpLayer = new gpNamespace.ScGoldJumpLayer();
//                scGoldDiamondJumpLayer.attr({
//                    x: 0,
//                    y: cc.winSize.height
//                });
//                tyModelLayer.addChild(scGoldDiamondJumpLayer);
//
//                scGoldDiamondJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;
        }
    },

    addPropExchangeContent: function (data) {
        this.isInit3 = true;
        var scLayer = this.scLayer;

        var itemArray = [];
        for (var a = 0; a < data.itemCount / 3; a++) {
            itemArray[a] = new cc.Sprite(gpNamespace.sc.Sc_wupingoumaiBackground);
        }

        for (var b = 0; b < data.itemCount; b++) {
            var row = b / 3;
            if (row.toString().indexOf(".") > 0)
                row = parseInt(row.toString().substr(0, row.toString().indexOf(".")));

            var goodIcon;
            if (data.goods[b][1] >= 4000 && data.goods[b][1] < 4017) {
                //实物图标
                var goodIconID = data.goods[b][1];
                var goodIconName = "#zjm_dj_" + this.getIconName(goodIconID, 3999) + "u.png";
                goodIcon = new cc.Sprite(goodIconName);
                goodIcon.attr({
                    x: 55 + 300 * (b % 3),
                    y: 35,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[row].addChild(goodIcon);
            }
            if (data.goods[b][1] == 0) {
                //实物图标
                var goodID = data.goods[b][0];
                goodIcon = new LoadHead(goodID);
                goodIcon.loadGood();
                goodIcon.attr({
                    x: 55 + 300 * (b % 3),
                    y: 35,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[row].addChild(goodIcon);
            }

            //道具名字
            var goodIconID = data.goods[b][1];
            var spriteName = "#zjm_scmc_" + this.getIconName(goodIconID, 3999) + "u.png";
            var name = new cc.Sprite(spriteName);
            name.attr({
                x: 260 + 300 * (b % 3),
                y: 125
            });
            itemArray[row].addChild(name);

            //购买
            var buyItem = new cc.MenuItemImage(gpNamespace.sc.Sc_buy, gpNamespace.sc.Sc_buy, this.buy3CallbackFunction, this);
            buyItem.attr({
                x: 135 / 2,
                y: 59 / 2
            });
            buyItem.setUserData([data.goods[b][0], data.goods[b][2], data.goods[b][6], data.goods[b][8]]);
            var buyMenu = new gpNamespace.TyMenu(buyItem);
            buyMenu.attr({
                x: 195 + 300 * (b % 3),
                y: 36
            });
            itemArray[row].addChild(buyMenu);
            buyMenu.setTouchArea(scLayer.scrollview3.touchArea);

            //价格背景
            var priceBackground = new cc.Sprite(gpNamespace.sc.Sc_wupingoumaiGoldBackground);
            if (data.goods[b][6] == gpNamespace.ScPriceType.Diamond)
                priceBackground = new cc.Sprite(gpNamespace.sc.Sc_wupingoumaiDiamondBackground);
            priceBackground.attr({
                x: 60 + 300 * (b % 3),
                y: -30,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[row].addChild(priceBackground);

            //价格数
            var price = new cc.LabelTTF(data.goods[b][2], "Arial", 25);
            price.attr({
                x: 215 + 300 * (b % 3),
                y: -2
            });
            itemArray[row].addChild(price);
        }

        scLayer.scrollview3.setMyContainer(itemArray, 290, 1);
    },

    buy3CallbackFunction: function (sender) {
        cc.log("购买3");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        //cc.log("data:" + data);

        var goodID = data[0];
        var priceQuantity = data[1];
        var priceType = data[2];
        var goodName = data[3];

        var runningScene = cc.director.getRunningScene();
        var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        var tyModelLayer = new gpNamespace.TyModelLayer();
        tyModelLayer.setTouchArea(cc.size(605, 451), cc.p(325, 161));
        tyModelLayer1.addChild(tyModelLayer);
        runningScene.addChild(tyModelLayer1, 10);

        var scBuyPropLayer = new gpNamespace.ScBuyDjLayer();
        scBuyPropLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(scBuyPropLayer);
        scBuyPropLayer.setGoodID(goodID);
        scBuyPropLayer.setPriceQuantity(priceQuantity);
        scBuyPropLayer.setPriceType(priceType);

        scBuyPropLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

        xinyou.netManager.getGoodInfo(goodID);

        this.setBuyPropLayer(scBuyPropLayer);
    },

    onMarketBuyDj: function (event) {
        cc.log("marketBuyDj");

        var marketBuyDj = event.getUserData();

        userInfo.gold = marketBuyDj.gold;
        userInfo.diamond = marketBuyDj.diamond;
        userInfo.voucher = marketBuyDj.voucher;
        
//        this.topLayer.removeChildByTag(101);
//        this.topLayer.removeChildByTag(102);
//        this.topLayer.removeChildByTag(103);
        this.topLayer && this.topLayer.setUserGold(marketBuyDj.gold);
        this.topLayer && this.topLayer.setUserDiamond(marketBuyDj.diamond);
        this.topLayer && this.topLayer.setUserVoucher(marketBuyDj.voucher);

//        this.topLayer.setUserGold(parseInt(marketBuyDj.gold));
//        this.topLayer.setUserDiamond(parseInt(marketBuyDj.diamond));
//        this.topLayer.setUserDui(parseInt(marketBuyDj.voucher));
//
//        this.userInfoLayer.setGold(marketBuyDj.gold);
//        this.userInfoLayer.setDiamond(marketBuyDj.diamond);
//        this.userInfoLayer.setDuihuanquan(marketBuyDj.diamond);

        switch (marketBuyDj.result) {
            case 0 : //成功
                cc.log("购买道具成功");

                /*gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinEffect, false);

                if (cc.sys.isObjectValid(this.vipLayer)) {
                    this.vipLayer.getParent().getParent().removeFromParent(true);
                }*/

                break;

            case 1: //钻石不足
            	cc.log("钻石不足");
//                var runningScene = cc.director.getRunningScene();
//                var tyModelLayer1 = new gpNamespace.TyModelLayer1();
//                var tyModelLayer = new gpNamespace.TyModelLayer();
//                tyModelLayer.setTouchArea(cc.size(576, 315), cc.p(352, 203));
//                tyModelLayer1.addChild(tyModelLayer);
//                runningScene.addChild(tyModelLayer1, 10);
//
//                var scDiamondJumpLayer = new gpNamespace.ScDiamondJumpLayer();
//                scDiamondJumpLayer.attr({
//                    x: 0,
//                    y: cc.winSize.height
//                });
//                tyModelLayer.addChild(scDiamondJumpLayer);
//
//                scDiamondJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;

            case 2: //兑换券不足
            	cc.log("兑换券不足");
//                var runningScene = cc.director.getRunningScene();
//                var tyModelLayer1 = new gpNamespace.TyModelLayer1();
//                var tyModelLayer = new gpNamespace.TyModelLayer();
//                tyModelLayer.setTouchArea(cc.size(576, 315), cc.p(352, 203));
//                tyModelLayer1.addChild(tyModelLayer);
//                runningScene.addChild(tyModelLayer1, 10);
//
//                var scVoucherJumpLayer = new gpNamespace.ScVoucherJumpLayer();
//                scVoucherJumpLayer.attr({
//                    x: 0,
//                    y: cc.winSize.height
//                });
//                tyModelLayer.addChild(scVoucherJumpLayer);
//
//                scVoucherJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;

            case 3: //金币不足
            	cc.log("金币不足");
//                var runningScene = cc.director.getRunningScene();
//                var tyModelLayer1 = new gpNamespace.TyModelLayer1();
//                var tyModelLayer = new gpNamespace.TyModelLayer();
//                tyModelLayer.setTouchArea(cc.size(576, 315), cc.p(352, 203));
//                tyModelLayer1.addChild(tyModelLayer);
//                runningScene.addChild(tyModelLayer1, 10);
//
//                var scGoldDiamondJumpLayer = new gpNamespace.ScGoldJumpLayer();
//                scGoldDiamondJumpLayer.attr({
//                    x: 0,
//                    y: cc.winSize.height
//                });
//                tyModelLayer.addChild(scGoldDiamondJumpLayer);
//
//                scGoldDiamondJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;
        }
    },

    addPhysicalExchangeContent: function (data) {
        this.isInit4 = true;
        var scLayer = this.scLayer;

        var itemArray = [];
        for (var a = 0; a < data.itemCount / 3; a++) {
            itemArray[a] = new cc.Sprite(gpNamespace.sc.Sc_wupingoumaiBackground);
        }

        for (var b = 0; b < data.itemCount; b++) {
            var row = b / 3;
            if (row.toString().indexOf(".") > 0)
                row = parseInt(row.toString().substr(0, row.toString().indexOf(".")));

            var goodIcon;
            if (data.goods[b][1] >= 5000 && data.goods[b][1] < 5062) {
                //实物图标
                var goodIconID = data.goods[b][1];
                var goodIconName = "#sc_swjp_" + this.getIconName(goodIconID, 4999) + "u.png";
                goodIcon = new cc.Sprite(goodIconName);
                goodIcon.attr({
                    x: 170 + 300 * (b % 3),
                    y: -35,
                    anchorX: 0.5,
                    anchorY: 0
                });
                itemArray[row].addChild(goodIcon, 1);
            }
            if (data.goods[b][1] == 0) {
                //实物图标
                var goodID = data.goods[b][0];
                goodIcon = new LoadHead(goodID);
                goodIcon.loadGood();
                goodIcon.attr({
                    x: 170 + 300 * (b % 3),
                    y: -35,
                    anchorX: 0.5,
                    anchorY: 0
                });
                itemArray[row].addChild(goodIcon, 1);
            }

            //热卖
            var goodState = data.goods[b][4];
            switch (goodState) {
                case 1:
                    var remai = new cc.Sprite(gpNamespace.sc.Sc_remai);
                    remai.attr({
                        x: 0,
                        y: goodIcon.getContentSize().height,
                        anchorX: 0,
                        anchorY: 1
                    });
                    goodIcon.addChild(remai);
                    break;
            }

            //兑换
            var duihuanItem = new cc.MenuItemImage(gpNamespace.sc.Sc_duihuan, gpNamespace.sc.Sc_duihuan, this.duihuanCallbackFunction, this);
            duihuanItem.attr({
                x: 120 / 2,
                y: 52 / 2
            });
            duihuanItem.setUserData([data.goods[b][0], data.goods[b][2], data.goods[b][8]]);
            var duihuanMenu = new gpNamespace.TyMenu(duihuanItem);
            duihuanMenu.attr({
                x: 105 + 300 * (b % 3),
                y: 15
            });
            itemArray[row].addChild(duihuanMenu, 2);
            duihuanMenu.setTouchArea(scLayer.scrollview4.touchArea);

            //兑换券背景
            var duihuanquanBackground = new cc.Sprite(gpNamespace.sc.Sc_shiwuduihuanDuihuanquanBackground);
            duihuanquanBackground.attr({
                x: 40 + 300 * (b % 3),
                y: -90,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[row].addChild(duihuanquanBackground);

            ////名字
            //var name = new cc.LabelTTF(data.goods[b][8], "Arial", 25);
            //name.attr({
            //    x: 165 + 300 * (b % 3),
            //    y: -20
            //});
            //itemArray[row].addChild(name);

            //价格数
            var price = new cc.LabelTTF(data.goods[b][2], "Arial", 25);
            price.attr({
                x: 190 + 300 * (b % 3),
                y: -62
            });
            itemArray[row].addChild(price);
        }

        scLayer.scrollview4.setMyContainer(itemArray, 330, 1);
    },

    duihuanCallbackFunction: function (sender) {
        cc.log("兑换");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        //cc.log("data:" + data);

        var goodID = data[0];
        var goodPrice = data[1];
        var goodName = data[2];

        var userName = cc.sys.localStorage.getItem(gpNamespace.USER_NAME);

        cc.log("userName:" + userName);

        if (!tyNamespace.checkStore(userName)) {
            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var scGuestJumpLayer = new gpNamespace.ScGuestJumpLayer();
            scGuestJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(scGuestJumpLayer);

            scGuestJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

            return;
        }

        var runningScene = cc.director.getRunningScene();
        var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        var tyModelLayer = new gpNamespace.TyModelLayer();
        tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
        tyModelLayer1.addChild(tyModelLayer);
        runningScene.addChild(tyModelLayer1, 10);

        var scDuiLayer = new gpNamespace.ScDuiLayer();
        scDuiLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(scDuiLayer);
        scDuiLayer.setGoodID(goodID);
        scDuiLayer.setGoodPrice(goodPrice);
        scDuiLayer.setGoodName(goodName);

        scDuiLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

        xinyou.netManager.getGoodInfo(goodID);

        this.setBuyVoucherLayer(scDuiLayer);
    },
    //购买实物
    onMarketBuySw: function (event) {
        cc.log("marketBuySw");

        var marketBuySw = event.getUserData();
        /*cc.log("diamond:" + marketBuySw.diamond);
        cc.log("voucher:" + marketBuySw.voucher);
        cc.log("gold:" + marketBuySw.gold);
        cc.log("code:" + marketBuySw.code);*/

        if (marketBuySw.code != "") {
        	cc.log("兑换实物成功");
        	//跳个弹窗
        	tyNamespace.tipsJumper(1,tyNamespace.TipsSectencesIndex.DuihunSuc);

        	//这里要先把MailLayer赋值为空，不然会有上次打开MailLayer的数据，而实际上MailLayer是空会爆！
        	gpNamespace.TyNetManager.getInstance().setMailLayer(null);//将本页面信息传给netManager
        	xinyou.netManager.getMail(1);//获取邮件列表，用于主页提示
        }else{
        	cc.log("兑换实物失败");
        }

//        this.topLayer.removeChildByTag(101);
//        this.topLayer.removeChildByTag(102);
//        this.topLayer.removeChildByTag(103);
        this.topLayer && this.topLayer.setUserGold(parseInt(marketBuySw.gold));
        this.topLayer && this.topLayer.setUserDiamond(parseInt(marketBuySw.diamond));
        this.topLayer && this.topLayer.setUserVoucher(parseInt(marketBuySw.voucher));

        //cc.sys.localStorage.setItem(gpNamespace.GOLD, marketBuySw.gold);
        //cc.sys.localStorage.setItem(gpNamespace.DIAMOND, marketBuySw.diamond);
        //cc.sys.localStorage.setItem(gpNamespace.VOUCHER, marketBuySw.voucher);

        userInfo.gold = marketBuySw.gold;
        userInfo.diamond = marketBuySw.diamond;
        userInfo.voucher = marketBuySw.voucher;

        /*if (marketBuySw.code != "") {
            cc.log("兑换实物成功");

            xinyou.netManager.getGameNotice();

            gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinEffect, false);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer = new gpNamespace.TyModelLayer();
            runningScene.addChild(tyModelLayer, 10);

            var scVoucherOKJumpLayer = new gpNamespace.ScVoucherOKJumpLayer();
            scVoucherOKJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(scVoucherOKJumpLayer);

            scVoucherOKJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }
        else {
            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(576, 315), cc.p(352, 203));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var scVoucherJumpLayer = new gpNamespace.ScVoucherJumpLayer();
            scVoucherJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(scVoucherJumpLayer);

            scVoucherJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }*/
    },

    onGoodInfo: function (event) {
        cc.log("onGoodInfo");

        var goodInfo = event.getUserData();

        //cc.log("content:" + goodInfo.content);

        var self = this;

        if (cc.sys.isObjectValid(this.buyGoldLayer)) {
            this.buyGoldLayer.scheduleOnce(function () {
                self.buyGoldLayer.setGoodInfo(goodInfo.content);
            }, 0.5);
        }

        if (cc.sys.isObjectValid(this.buyPropLayer)) {
            this.buyPropLayer.scheduleOnce(function () {
                self.buyPropLayer.setGoodInfo(goodInfo.content);
            }, 0.5);
        }

        if (cc.sys.isObjectValid(this.buyVoucherLayer)) {
            this.buyVoucherLayer.scheduleOnce(function () {
                self.buyVoucherLayer.setGoodInfo(goodInfo.content);
            }, 0.5);
        }

        if (cc.sys.isObjectValid(this.userPropLayer)) {
            this.userPropLayer.scheduleOnce(function () {
                self.userPropLayer.setGoodInfo(goodInfo.content);
            }, 0.5);
        }
    },
    
    onMyProp: function (event) {
    	cc.log("onMyProp");

    	var myProp = event.getUserData();

    	//cc.log("goodCount:" + myProp.goodCount);
    	//for (var a = 0; a < myProp.goodCount; a++) {
    	//    cc.log("goodIconID:" + myProp.props[a][0]);
    	//    cc.log("goodID:" + myProp.props[a][1]);
    	//    cc.log("goodQuantity:" + myProp.props[a][2]);
    	//    cc.log("goodState:" + myProp.props[a][3]);
    	//    cc.log("goodUseState:" + myProp.props[a][4]);
    	//    cc.log("goodIconPath:" + myProp.props[a][5]);
    	//    cc.log("goodName:" + myProp.props[a][6]);
    	//    cc.log("-----------------------------");
    	//}

    	gpNamespace.MyPropInfo.ITEMCOUNT = myProp.goodCount;
    	gpNamespace.MyPropInfo.PROPS = [];
    	for (var a = 0; a < gpNamespace.MyPropInfo.ITEMCOUNT; a++) {
    		gpNamespace.MyPropInfo.PROPS[a] = [];
    		gpNamespace.MyPropInfo.PROPS[a][0] = myProp.props[a][0];
    		gpNamespace.MyPropInfo.PROPS[a][1] = myProp.props[a][1];
    		gpNamespace.MyPropInfo.PROPS[a][2] = myProp.props[a][2];
    		gpNamespace.MyPropInfo.PROPS[a][3] = myProp.props[a][3];
    		gpNamespace.MyPropInfo.PROPS[a][4] = myProp.props[a][4];
    		gpNamespace.MyPropInfo.PROPS[a][5] = myProp.props[a][5];
    		gpNamespace.MyPropInfo.PROPS[a][6] = myProp.props[a][6];
    	}

    	switch (gpNamespace.myPropFrom) {
    	case gpNamespace.MyPropFrom.UserInfo:
    		this.userInfoLayer.setMyProp();
    		break;

    	case gpNamespace.MyPropFrom.Game:
    		this.gamePropLayer.setMyProp();
    		break;
    	}

    	tyNamespace.removeWaitLayer();
    },

//    onMyProp: function (event) {
//        cc.log("onMyProp");
//
//        var prop = event.getUserData();
//        var userInfoLayer = this.userInfoLayer;
//        var innerUserPropLayer = this.innerUserPropLayer;
//
//        //cc.log("goodCount:" + prop.goodCount);
//        //for (var a = 0; a < prop.goodCount; a++) {
//        //    cc.log("goodIconID:" + prop.props[a][0]);
//        //    cc.log("goodID:" + prop.props[a][1]);
//        //    cc.log("goodQuantity:" + prop.props[a][2]);
//        //    cc.log("goodState:" + prop.props[a][3]);
//        //    cc.log("goodUseState:" + prop.props[a][4]);
//        //    cc.log("goodIconPath:" + prop.props[a][5]);
//        //    cc.log("goodName:" + prop.props[a][6]);
//        //    cc.log("-----------------------------");
//        //}
//
//        gpNamespace.TyPropData = [];
//        for (var a = 0; a < prop.goodCount; a++) {
//            gpNamespace.TyPropData[a] = [];
//            gpNamespace.TyPropData[a][0] = prop.props[a][0];
//            gpNamespace.TyPropData[a][1] = prop.props[a][1];
//            gpNamespace.TyPropData[a][2] = prop.props[a][2];
//            gpNamespace.TyPropData[a][3] = prop.props[a][3];
//            gpNamespace.TyPropData[a][4] = prop.props[a][4];
//            gpNamespace.TyPropData[a][5] = prop.props[a][5];
//            gpNamespace.TyPropData[a][6] = prop.props[a][6];
//        }
//
//        //cc.log("gpNamespace.TyPropData:" + gpNamespace.TyPropData.length);
//        //for (var a = 0; a < gpNamespace.TyPropData.length; a++) {
//        //    cc.log("gpNamespace.TyPropData[a][0]:" + gpNamespace.TyPropData[a][0]);
//        //    cc.log("gpNamespace.TyPropData[a][1]:" + gpNamespace.TyPropData[a][1]);
//        //    cc.log("gpNamespace.TyPropData[a][2]:" + gpNamespace.TyPropData[a][2]);
//        //    cc.log("gpNamespace.TyPropData[a][3]:" + gpNamespace.TyPropData[a][3]);
//        //    cc.log("gpNamespace.TyPropData[a][4]:" + gpNamespace.TyPropData[a][4]);
//        //    cc.log("gpNamespace.TyPropData[a][5]:" + gpNamespace.TyPropData[a][5]);
//        //    cc.log("gpNamespace.TyPropData[a][6]:" + gpNamespace.TyPropData[a][6]);
//        //    cc.log("-----------------------------");
//        //}
//
//        if (cc.sys.isObjectValid(userInfoLayer)) {
//            userInfoLayer.scrollview.clearContainer();
//
//            var itemArray = [];
//            for (var a = 0; a < prop.goodCount; a++) {
//                itemArray[a] = new cc.Sprite(gpNamespace.grxx.Grxx_myPropBackground);
//
//                //道具图标
//                var goodIcon;
//                if (prop.props[a][0] >= 4000 && prop.props[a][0] < 4017) {
//                    //实物图标
//                    var goodIconID = prop.props[a][0];
//                    var goodIconName = "#zjm_dj_" + this.getIconName(goodIconID, 3999) + "u.png";
//                    goodIcon = new cc.Sprite(goodIconName);
//                    goodIcon.attr({
//                        x: 85,
//                        y: 110
//                    });
//                    goodIcon.setScale(0.75);
//                    itemArray[a].addChild(goodIcon, 1);
//                }
//                if (prop.props[a][0] == 0) {
//                    //实物图标
//                    var goodID = prop.props[a][1];
//                    goodIcon = new LoadHead(goodID);
//                    goodIcon.loadGood();
//                    goodIcon.attr({
//                        x: 85,
//                        y: 110
//                    });
//                    goodIcon.setScale(0.75);
//                    itemArray[a].addChild(goodIcon, 1);
//                }
//
//                //道具说明
//                var propName = new cc.LabelTTF(prop.props[a][6] + "(" + prop.props[a][2] + "个)", "Arial", 18);
//                propName.attr({
//                    x: 85,
//                    y: 44
//                });
//                itemArray[a].addChild(propName);
//
//                //道具按钮
//                var item = new cc.MenuItemImage(gpNamespace.grxx.Grxx_itemMenu, gpNamespace.grxx.Grxx_itemMenu, this.propCallbackFunction, this);
//                item.attr({
//                    x: 161 / 2,
//                    y: 162 / 2
//                });
//                item.setUserData([prop.props[a][1], prop.props[a][6], prop.props[a][4]]);
//                var menu = new gpNamespace.TyMenu(item);
//                menu.attr({
//                    x: 6,
//                    y: 10
//                });
//                itemArray[a].addChild(menu);
//                menu.setTouchArea(userInfoLayer.scrollview.touchArea);
//                menu.setTouchListener();
//            }
//            userInfoLayer.scrollview.setMyContainer(itemArray, 186, 4);
//        }
//
//        if (cc.sys.isObjectValid(innerUserPropLayer)) {
//            innerUserPropLayer.scrollview.clearContainer();
//
//            var itemArray = [];
//            for (var a = 0; a < prop.goodCount; a++) {
//                itemArray[a] = new cc.Sprite(gpNamespace.grxx.Grxx_myPropBackground);
//
//                //道具图标
//                var goodIcon;
//                if (prop.props[a][0] >= 4000 && prop.props[a][0] < 4017) {
//                    //实物图标
//                    var goodIconID = prop.props[a][0];
//                    var goodIconName = "#zjm_dj_" + this.getIconName(goodIconID, 3999) + "u.png";
//                    goodIcon = new cc.Sprite(goodIconName);
//                    goodIcon.attr({
//                        x: 85,
//                        y: 110
//                    });
//                    goodIcon.setScale(0.75);
//                    itemArray[a].addChild(goodIcon, 1);
//                }
//                if (prop.props[a][0] == 0) {
//                    //实物图标
//                    var goodID = prop.props[a][1];
//                    goodIcon = new LoadHead(goodID);
//                    goodIcon.loadGood();
//                    goodIcon.attr({
//                        x: 85,
//                        y: 110
//                    });
//                    goodIcon.setScale(0.75);
//                    itemArray[a].addChild(goodIcon, 1);
//                }
//
//                //道具说明
//                var propName = new cc.LabelTTF(prop.props[a][6] + "(" + prop.props[a][2] + "个)", "Arial", 18);
//                propName.attr({
//                    x: 85,
//                    y: 44
//                });
//                itemArray[a].addChild(propName);
//
//                ////道具按钮
//                //var item = new cc.MenuItemImage(gpNamespace.grxx.Grxx_itemMenu, gpNamespace.grxx.Grxx_itemMenu, this.propCallbackFunction, this);
//                //item.attr({
//                //    x: 161 / 2,
//                //    y: 162 / 2
//                //});
//                //item.setUserData([prop.props[a][1], prop.props[a][6], prop.props[a][4]]);
//                //var menu = new gpNamespace.TyMenu(item);
//                //menu.attr({
//                //    x: 6,
//                //    y: 10
//                //});
//                //itemArray[a].addChild(menu);
//                //menu.setTouchArea(userInfoLayer.scrollview.touchArea);
//                //menu.setTouchListener();
//            }
//            innerUserPropLayer.scrollview.setMyContainer(itemArray, 186, 4);
//        }
//    },

    propCallbackFunction: function (sender) {
        cc.log("外部道具");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        tyNamespace.setMenuEnable(sender);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();
        var goodID = data[0];
        var goodName = data[1];
        var goodUseState = data[2];

        var runningScene = cc.director.getRunningScene();
        var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        var tyModelLayer = new gpNamespace.TyModelLayer();
        tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
        tyModelLayer1.addChild(tyModelLayer);
        runningScene.addChild(tyModelLayer1, 10);

        var tyMyPropJumpLayer = new gpNamespace.TyMyPropJumpLayer();
        tyMyPropJumpLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(tyMyPropJumpLayer);
        tyMyPropJumpLayer.setGoodID(goodID);
        tyMyPropJumpLayer.setGoodName(goodName);
        tyMyPropJumpLayer.setMenuState(goodUseState);
        tyMyPropJumpLayer.setParentNode(this.userInfoLayer);

        tyMyPropJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

        xinyou.netManager.getGoodInfo(goodID);

        this.setUserPropLayer(tyMyPropJumpLayer);
    },

    onUseLaba: function (event) {
        cc.log("onUseLaba");

        var useLaba = event.getUserData();

        cc.log("chatType:" + useLaba.chatType);
        cc.log("userId:" + useLaba.userId);
        cc.log("chatContent:" + useLaba.chatContent);
        cc.log("nickName:" + useLaba.nickName);

        /*var labaLayer = this.labaLayer;

        gpNamespace.TyGonggaoData.push(useLaba.nickName + ":" + useLaba.chatContent + "|" + useLaba.chatType);
        if (gpNamespace.TyGonggaoData.length > 3)
            gpNamespace.TyGonggaoData.shift();

        gpNamespace.TyGonggaoDataIndex = 1;

        var singleLength = 66;
        var singleHeight = 30;

        gpNamespace.TyTalkData = [];
        var firstStr = "[" + useLaba.nickName + "]:";
        var secondStr = useLaba.chatContent;
        var str = firstStr + secondStr;
        var strArray = gpNamespace.GetSlicedArray(str, singleLength);

        for (var a = 0; a < strArray.length; a++) {
            var str = "";
            var isSelf = 0;
            var nickName = userInfo.nickName;
            if (useLaba.nickName == nickName)
                isSelf = 1;
            if (firstStr == strArray[a].substr(0, firstStr.length)) {
                str = strArray[a] + "|" + firstStr + "|" + useLaba.nickName + "|" + useLaba.userID + "|" + useLaba.chatType + "|" + isSelf;
                gpNamespace.TyLabaData.push(str);
            }
            else {
                str = strArray[a] + "|" + "" + "|" + "" + "|" + 0 + "|" + useLaba.chatType + "|" + isSelf;
                gpNamespace.TyLabaData.push(str);
            }
        }

        if (!cc.sys.isObjectValid(labaLayer))
            return;

        labaLayer.scrollview.clearContainer();

        for (var a = 0; a < gpNamespace.TyLabaData.length; a++) {
            labaLayer.scrollview.addLine(singleHeight);
            var tag = labaLayer.scrollview.rowIndex;
            var item = labaLayer.scrollview.container.getChildByTag(tag);

            var strArray = gpNamespace.TyLabaData[a].split("|");

            var label = new cc.LabelTTF(strArray[0], "Arial", 25);
            switch (strArray[4]) {
                case "1": // 私聊
                    label.setFontFillColor(cc.color(210, 97, 195, 255));
                    break;
                case "2": // 公聊
                    //if (strArray[5] == 0)
                    label.setFontFillColor(cc.color(6, 255, 0, 255));
                    break;
                case "3": // 系统
                    label.setFontFillColor(cc.color(241, 211, 43, 255));
                    break;
            }
            label.attr({
                x: 0,
                y: 0,
                anchorX: 0,
                anchorY: 0
            });
            item.addChild(label);
        }*/
    },

    onPokeCount: function (event) {
        cc.log("onPokeCount");

        var poke = event.getUserData();

        //cc.log("result:" + poke.result);
        //cc.log("pokeType:" + poke.pokeType);

        if (poke.result == 1) {
            var remainsShow = new cc.Sprite("#ddz_jpq_002u.png");
            remainsShow.attr({
                x: 640,
                y: 111
            });
            this.ddzGameLayer.addChild(remainsShow, 10, "remainsShow");

            this.ddzGameLayer.updateCardsRemain();
        }
        else {
            if (poke.pokeType == 1) {
                gpNamespace.showDialog("您目前没有记牌器可以使用！");

                //var runningScene = cc.director.getRunningScene();
                //var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                //tyJumpLayerWithText.attr({
                //    x: 0,
                //    y: cc.winSize.height
                //});
                //runningScene.addChild(tyJumpLayerWithText, 50);
                //tyJumpLayerWithText.setLabelText("您目前没有该道具可以使用！");
                //
                //tyJumpLayerWithText.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
            }
        }
    },

    onBeforeUseProp: function (event) {
    	cc.log("onBeforeUseProp");

    	var usePropBefore = event.getUserData();

    	//cc.log("goodID:" + usePropBefore.goodID);
    	//cc.log("goodPrice:" + usePropBefore.goodPrice);
    	//cc.log("goodPriceType:" + usePropBefore.goodPriceType);
    	//cc.log("goodRestCount:" + usePropBefore.goodRestCount);

    	gpNamespace.UsePropBeforeInfo.GOODID = usePropBefore.goodID;
    	gpNamespace.UsePropBeforeInfo.GOODPRICE = usePropBefore.goodPrice;
    	gpNamespace.UsePropBeforeInfo.GOODPRICETYPE = usePropBefore.goodPriceType;
    	gpNamespace.UsePropBeforeInfo.GOODRESTCOUNT = usePropBefore.goodRestCount;

    	switch (gpNamespace.UsePropBeforeInfo.GOODID) {
    	case 39:
    		this.sjpdLayer.setLabaInfo(gpNamespace.UsePropBeforeInfo.GOODRESTCOUNT);
    		break;

    	case 57:
    		this.gameLayer.setXuezhanInfo();
    		break;
    	}

    	tyNamespace.removeWaitLayer();
    },

    onUseProp: function (event) {
    	cc.log("onUseProp");

    	var useProp = event.getUserData();

    	//cc.log("diamond:" + useProp.diamond);
    	//cc.log("cansaiquan:" + useProp.cansaiquan);
    	//cc.log("voucher:" + useProp.voucher);
    	//cc.log("gold:" + useProp.gold);
    	//cc.log("result:" + useProp.result);
    	//cc.log("goodID:" + useProp.goodID);

    	gpNamespace.UsePropInfo.DIAMOND = useProp.diamond;
    	gpNamespace.UsePropInfo.CANSAIQUAN = useProp.cansaiquan;
    	gpNamespace.UsePropInfo.VOUCHER = useProp.voucher;
    	gpNamespace.UsePropInfo.GOLD = useProp.gold;
    	gpNamespace.UsePropInfo.RESULT = useProp.result;
    	gpNamespace.UsePropInfo.GOODID = useProp.goodID;

    	if (gpNamespace.UsePropInfo.RESULT != 1)
    		tyNamespace.addJumpLayer(tyNamespace.JumpType.UsePropFail, function () {
    		}, this);
    	else {
    		userInfo.gold = gpNamespace.UsePropInfo.GOLD;
    		userInfo.diamond = gpNamespace.UsePropInfo.DIAMOND;
    		userInfo.voucher = gpNamespace.UsePropInfo.VOUCHER;

    		var runningScene = cc.director.getRunningScene();
    		if (runningScene.sceneName == gpNamespace.MainSceneName) {
    			this.topLayer.setUserGold(userInfo.gold);
    			this.topLayer.setUserDiamond(userInfo.diamond);
    			this.topLayer.setUserVoucher(userInfo.voucher);
    		}

    		switch (gpNamespace.UsePropInfo.GOODID) {
    		case 39://喇叭
//    			this.labaLayer.setUseLabaInfo();
    			cc.log("喇叭使用成功");
    			xinyou.netManager.getHistroyLaba();

    			break;

    		case 57://血战卡
    			gpNamespace.gameStart = true;
    			gpNamespace.gameEnd = false;

    			this.gameLayer.setUseXuezhanInfo();

    			break;

    			//内部道具
    		case 44://臭鸡蛋
    			gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.Egg, false);
    			this.innerUserInfoLayer.getParent().getParent().removeFromParent(true);
    			break;

    		case 45://鲜花
    			gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.HuaEffect, false);
    			this.innerUserInfoLayer.getParent().getParent().removeFromParent(true);
    			break;

    		case 46://炸弹
    			this.innerUserInfoLayer.getParent().getParent().removeFromParent(true);
    			this.gameLayer.scheduleOnce(function () {
    				gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.Boom, false);
    			}, 0.6);

    			break;

    		case 47://红唇
    			gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.Kiss, false);
    			this.innerUserInfoLayer.getParent().getParent().removeFromParent(true);
    			break;
    		}
    	}

    	tyNamespace.removeWaitLayer();
    },

    onUsePropResult: function (event) {
    	cc.log("onUsePropResult");

    	var propResult = event.getUserData();

    	//cc.log("fromIndex:" + propResult.fromIndex);
    	//cc.log("toIndex:" + propResult.toIndex);
    	//cc.log("goodID:" + propResult.goodID);
    	//cc.log("isUseMoney:" + propResult.isUseMoney);
    	//cc.log("goodPrice:" + propResult.goodPrice);

    	if (propResult.result == 0) {
    		tyNamespace.addTextRemoveLayer("使用道具失败!");

    		return;
    	}

    	if (!currentNetManager)
    		return;

    	if (!currentNetManager.getPlayerByChairID(propResult.fromIndex) || !currentNetManager.getPlayerByChairID(propResult.fromIndex).userItem)
    		return;
    	var senderNickName = currentNetManager.getPlayerByChairID(propResult.fromIndex).userItem.nickName;
    	if (!currentNetManager.getPlayerByChairID(propResult.toIndex) || !currentNetManager.getPlayerByChairID(propResult.toIndex).userItem)
    		return;
    	var receiverNickName = currentNetManager.getPlayerByChairID(propResult.toIndex).userItem.nickName;
    	var index = propResult.toIndex;
    	var position = cc.p(0, 0);
//    	if (gpNamespace.roomType == 0 || gpNamespace.roomType == 1) {
    		if (!currentNetManager.players[index])
    			return;
    		position = cc.p(currentNetManager.players[index].playLayer.headArmaturePoint.x, currentNetManager.players[index].playLayer.headArmaturePoint.y);
//    	}

    		cc.log("position.x:" + position.x + "----position.y:" + position.y + ",index" + index);

    	switch (propResult.goodID) {
    	case 57:
    		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.HuaEffect, false);
    		tyNamespace.addTextRemoveLayer(senderNickName + "使用了血战卡!", 150);

    		this.gameEndLayer.getParent().removeFromParent(true);
    		break;

    	case 44:
    		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.Egg, false);
    		tyNamespace.addTextRemoveLayer(senderNickName + "对" + receiverNickName + "使用了臭鸡蛋!", 150);

    		var armature = new ccs.Armature("dh_npc_01u");
    		armature.getAnimation().playWithIndex(3);
    		armature.getAnimation().setSpeedScale(1);
    		armature.setScale(1);
    		armature.setAnchorPoint(0.5, 0.5);
    		armature.setPosition(position);
    		currentNetManager.tableLayer.addChild(armature, 1021);
    		armature.getAnimation().setMovementEventCallFunc(this.callBackRemove, currentNetManager.tableLayer);

    		if (currentNetManager.useGold) {
    			if (!propResult.isUseMoney) {
    				var player = currentNetManager.getPlayerByChairID(propResult.fromIndex);
    				player.userItem.lScore -= propResult.goodPrice;
    				player.playLayer.setScore(player.userItem.lScore.toString());
    			}
    		}

    		break;

    	case 45:
    		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.HuaEffect, false);
    		tyNamespace.addTextRemoveLayer(senderNickName + "对" + receiverNickName + "使用了鲜花!", 150);

    		var armature = new ccs.Armature("dh_npc_01u");
    		armature.getAnimation().playWithIndex(2);
    		armature.getAnimation().setSpeedScale(1);
    		armature.setScale(1);
    		armature.setAnchorPoint(0.5, 0.5);
    		armature.setPosition(position);
    		currentNetManager.tableLayer.addChild(armature, 1021);
    		armature.getAnimation().setMovementEventCallFunc(this.callBackRemove, currentNetManager.tableLayer);

    		if (currentNetManager.useGold) {
    			if (!propResult.isUseMoney) {
    				var player = currentNetManager.getPlayerByChairID(propResult.fromIndex);
    				player.userItem.lScore -= propResult.goodPrice;
    				player.playLayer.setScore(player.userItem.lScore.toString());
    			}
    		}

    		break;

    	case 46:
    		currentNetManager.tableLayer.scheduleOnce(function () {
    			gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.Boom, false);
    		}, 0.6);
    		cc.log("addTextRemoveLayer1");
    		tyNamespace.addTextRemoveLayer(senderNickName + "对" + receiverNickName + "使用了炸弹!", 150);
    		cc.log("addTextRemoveLayer2");
    		var armature = new ccs.Armature("dh_npc_01u");
    		armature.getAnimation().playWithIndex(0);
    		armature.getAnimation().setSpeedScale(1);
    		armature.setScale(1);
    		armature.setAnchorPoint(0.5, 0.5);
    		armature.setPosition(position);
    		currentNetManager.tableLayer.addChild(armature, 1021);
    		armature.getAnimation().setMovementEventCallFunc(this.callBackRemove, currentNetManager.tableLayer);

    		if (currentNetManager.useGold) {
    			if (!propResult.isUseMoney) {
    				var player = currentNetManager.getPlayerByChairID(propResult.fromIndex);
    				player.userItem.lScore -= propResult.goodPrice;
    				player.playLayer.setScore(player.userItem.lScore.toString());
    			}
    		}

    		break;

    	case 47:
    		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.HuaEffect, false);

    		tyNamespace.addTextRemoveLayer(senderNickName + "对" + receiverNickName + "使用了红唇!", 150);

    		var armature = new ccs.Armature("dh_npc_01u");
    		armature.getAnimation().playWithIndex(1);
    		armature.getAnimation().setSpeedScale(1);
    		armature.setScale(1);
    		armature.setAnchorPoint(0.5, 0.5);
    		armature.setPosition(position);
    		currentNetManager.tableLayer.addChild(armature, 1021);
    		armature.getAnimation().setMovementEventCallFunc(this.callBackRemove, currentNetManager.tableLayer);

    		if (currentNetManager.useGold) {
    			if (!propResult.isUseMoney) {
    				var player = currentNetManager.getPlayerByChairID(propResult.fromIndex);
    				player.userItem.lScore -= propResult.goodPrice;
    				player.playLayer.setScore(player.userItem.lScore.toString());
    			}
    		}

    		break;
    	}
    },

    //获取我的签到信息
    onMySign: function (event) {
        cc.log("onMySign");
        var sign = event.getUserData();
        signInfo = sign;//放到global中
        cc.log("个数 :"+sign.itemCount);
        this.signInit = true;
        var signLayer = this.signLayer;
        
        //签到天数
        signLayer.setSignInfo();
        gpNamespace.signDays = sign.signCount;
        
        cc.log("signInfo.signs"+signInfo.signs.length);
        
        for(var i=0; i<signInfo.signs.length; i++){
        	cc.log("是否可领："+signInfo.signs[i][2]);
        }
        
        //漏签天数
//        signLayer.setBuSignCount(sign.lostSignCount);
//        gpNamespace.buSignDays = sign.lostSignCount;

//        gpNamespace.vipFreeBuSign = sign.vipFreeBuSign;

        /*if (sign.vipFreeBuSign > 0) {
            signLayer.buSignMenu.setVisible(false);
            signLayer.vipBuSignMenu.setVisible(true);

            signLayer.addFreeDay(sign.vipFreeBuSign);
        } else {
            signLayer.buSignMenu.setVisible(true);
            signLayer.vipBuSignMenu.setVisible(false);

            if (signLayer.buSignCountLabel.getString() == "0") {
                if (userInfo.isVip) {
                    signLayer.isVIPBuSign.setVisible(true);
                    signLayer.buSignMenu.setVisible(false);
                }
                else {
                    signLayer.isBuSign.setVisible(true);
                    signLayer.buSignMenu.setVisible(false);
                }
            }
        }

        if (!sign.canSign) {
            if (userInfo.isVip) {
                signLayer.VIPSignMenu.setVisible(false);
                signLayer.isVIPSign.setVisible(true);
            } else {
                signLayer.signMenu.setVisible(false);
                signLayer.isSign.setVisible(true);
            }
        }

        if (!sign.lostSignCount) {
            if (userInfo.isVip) {
                signLayer.buSignMenu.setVisible(false);
                signLayer.isVIPBuSign.setVisible(true);
            } else {
                signLayer.buSignMenu.setVisible(false);
                signLayer.isBuSign.setVisible(true);
            }
        }

        var itemArray = [];
        for (var a = 0; a < sign.itemCount; a++) {
            itemArray[a] = new cc.Sprite(gpNamespace.ty.Ty_dot);

            //背景边框
            var back = new cc.Sprite(gpNamespace.sign.Sign_item1Background);
            if (a >= 3)
                back = new cc.Sprite(gpNamespace.sign.Sign_item2Background);
            back.attr({
                x: 0,
                y: 23
            });
            itemArray[a].addChild(back);

            //金币 兑换券 图标
            var spriteName = "#zjm_qd_0" + (a + 16) + "u.png";
            var img = new cc.Sprite(spriteName);
            img.attr({
                x: 68,
                y: 60
            });
            back.addChild(img);

            //信息背景
            var infoBack = new cc.Sprite(gpNamespace.sign.Sign_infoBackground);
            infoBack.attr({
                x: 68,
                y: -25
            });
            back.addChild(infoBack);

            //信息说明
            if (sign.signs[a][5]) {
                var info = new cc.LabelTTF(sign.signs[a][5].toString() + "次签到礼包", "Arial", 23);
                info.attr({
                    x: 84,
                    y: 22
                });
                infoBack.addChild(info);
            }

            if (sign.signs[a][0]) {
                var info = new cc.LabelTTF("连续" + sign.signs[a][0].toString() + "次签到", "Arial", 23);
                info.attr({
                    x: 84,
                    y: 22
                });
                infoBack.addChild(info);
            }

            //红色帷幕
            var red = new cc.Sprite(gpNamespace.sign.Sign_itemRedGold);
            red.attr({
                x: 68,
                y: 20
            });
            back.addChild(red, 2);

            //奖励单位
            var spriteName1 = "#zjm_qd_028u.png";
            var spritePosition = cc.p(103, 14);
            if (a >= 3) {
                spriteName1 = "#zjm_qd_029u.png";
                spritePosition = cc.p(58, 14);
            }
            var label = new cc.Sprite(spriteName1);
            label.attr({
                x: spritePosition.x,
                y: spritePosition.y,
                anchorX: 0,
                anchorY: 0
            });
            red.addChild(label);

            //奖励数额
            for (var i = sign.signs[a][2].toString().length, j = 0; i > 0; i--, j++) {
                var str = parseInt(sign.signs[a][2].toString().substr(i - 1, 1)) + 40;
                var spritName = "#zjm_qd_0" + str + "u.png";
                var spritePosition = cc.p(85, 13);
                if (a >= 3)
                    spritePosition = cc.p(40, 13);
                var countCell = new cc.Sprite(spritName);
                countCell.attr({
                    x: spritePosition.x - 15 * j,
                    y: spritePosition.y,
                    anchorX: 0,
                    anchorY: 0
                });
                red.addChild(countCell);
            }

            //领取签到奖励
            var buttonItem = new cc.MenuItemImage(gpNamespace.sign.Sign_model, gpNamespace.sign.Sign_model, this.clickCallbackFunction, this);
            buttonItem.attr({
                x: 0,
                y: 0
            });
            buttonItem.setUserData([sign.signs[a][2], sign.signs[a][3]]);
            var buttonMenu = new cc.Menu(buttonItem);
            buttonMenu.attr({
                x: 0,
                y: 18
            });
            itemArray[a].addChild(buttonMenu);

            //可以领取
            var canGet = new cc.Sprite(gpNamespace.sign.Sign_unreceived);
            canGet.attr({
                x: 0,
                y: 66
            });
            itemArray[a].addChild(canGet);
            canGet.setVisible(false);
            canGet.setTag(10 + a);

            //已领取
            var isGet = new cc.Sprite(gpNamespace.sign.Sign_received);
            isGet.attr({
                x: 0,
                y: 66
            });
            itemArray[a].addChild(isGet);
            isGet.setVisible(false);
            isGet.setTag(20 + a);

            //灰色遮罩
            var grayItem = new cc.MenuItemImage(gpNamespace.sign.Sign_gray, gpNamespace.sign.Sign_gray, this.grayCallbackFunction, this);
            grayItem.attr({
                x: 0,
                y: 0
            });
            var grayMenu = new cc.Menu(grayItem);
            grayMenu.attr({
                x: 0,
                y: 18
            });
            itemArray[a].addChild(grayMenu);
            grayMenu.setTag(a);

            if (sign.signs[a][4] == 1) {
                var sprite = itemArray[a].getChildByTag(10 + a);
                sprite.setVisible(true);
            }

            if (sign.signs[a][4] == 2) {
                var sprite = itemArray[a].getChildByTag(20 + a);
                sprite.setVisible(true);
            }

            if (sign.signs[a][4] == 1) {
                var menu = itemArray[a].getChildByTag(a);
                menu.setVisible(false);
            }
        }
        signLayer.scrollview.setMyContainer(itemArray, 200, 3);*/
    },

    clickCallbackFunction: function (sender) {
        cc.log("签到");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinEffect, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();
        var rewardCount = data[0];
        var id = data[1];

        //参赛券表现--------------------------------------------------------------
        var runningScene = cc.director.getRunningScene();
        var jumpLayer = new cc.Layer();
        runningScene.addChild(jumpLayer, 10);

        var spriteName = "";
        switch (id) {
            case 1:
            case 2:
            case 3:
                spriteName = "#mj_ty_70.png";
                break;
            case 4:
            case 5:
            case 6:
                spriteName = "#mj_ty_72.png";
                break;
        }

        var gold = new cc.Sprite(spriteName);
        gold.attr({
            x: 520,
            y: 560
        });
        jumpLayer.addChild(gold);
        gold.setScale(0.6);

        //乘号
        var plusName = "#zuos_030u.png";
        var plus = new cc.Sprite(plusName);
        plus.attr({
            x: 590,
            y: 560
        });
        jumpLayer.addChild(plus);

        //数量
        var count = rewardCount;
        for (var i = 0; i < count.toString().length; i++) {
            var str = parseInt(count.toString().substr(i, 1)) + 20;
            var spritName = "#zuos_0" + str + "u.png";
            var countCell = new cc.Sprite(spritName);
            countCell.attr({
                x: 620 + 24 * i,
                y: 560
            });
            jumpLayer.addChild(countCell);
        }

        var runningScene = cc.director.getRunningScene();
        var runningArmature = new ccs.Armature("coins");
        runningArmature.getAnimation().playWithIndex(0);
        runningArmature.getAnimation().setSpeedScale(1);
        runningArmature.setScale(1);
        runningArmature.setAnchorPoint(0.5, 0.5);
        runningArmature.setPosition(560, 580);
        runningScene.addChild(runningArmature, 10);
        runningArmature.getAnimation().setMovementEventCallFunc(this.callBackRemove, runningScene);

        jumpLayer.runAction(cc.sequence(cc.spawn(cc.moveBy(1.5, 0, 60), cc.fadeOut(1.5)), cc.callFunc(function () {
            jumpLayer.removeFromParent(true);
        })));
        //-------------------------------------------------------------------------

        xinyou.netManager.duihuan(id);
    },

    grayCallbackFunction: function () {
        cc.log("遮挡");
    },
//连续签到奖励
    onGetSign: function (event) {
        cc.log("onGetSign");

        var getSign = event.getUserData();
        var signLayer = this.signLayer;

        cc.log("金币" + getSign.gold);
        cc.log("钻石" + getSign.diamond);
        cc.log("兑换券" + getSign.voucher);
        cc.log("结果" + getSign.result);// 0 成功  1 领取过  2 未达到
        cc.log("getSign.itemCount"+getSign.itemCount);
        
        if (getSign.result == 0) {
//        	this.topLayer.removeChildByTag(101);
//        	this.topLayer.removeChildByTag(102);
//        	this.topLayer.removeChildByTag(103);
        	this.topLayer && this.topLayer.setUserGold(getSign.gold);
        	this.topLayer && this.topLayer.setUserDiamond(getSign.diamond);
        	this.topLayer && this.topLayer.setUserVoucher(getSign.voucher);

        	userInfo.gold = getSign.gold;
        	userInfo.diamond = getSign.diamond;
        	userInfo.voucher = getSign.voucher;
        	
        	for(var a = 0; a < getSign.itemCount; a++){
        		cc.log("奖励类别"+getSign.rewards[a][1]);
        	}
        	signLayer.showRewards(userInfo.isVip,true);
        }else if(getSign.result == 1){
        	for(var a = 0; a < getSign.itemCount; a++){
        		cc.log("奖励类别"+getSign.rewards[a][1]);
        	}
        	cc.log("你已经领取过");
        }else if(getSign.result == 2){
        	cc.log("你还未达到领取条件");
        }

        /*if (getSign.result == 0) {
            for (var a = 0; a < getSign.itemCount; a++) {
                var item = signLayer.scrollview.array[a];

                if (getSign.rewards[a][1] == 1) {
                    var sprite = item.getChildByTag(10 + a);
                    sprite.setVisible(true);
                }

                if (getSign.rewards[a][1] == 2) {
                    var sprite = item.getChildByTag(20 + a);
                    sprite.setVisible(true);
                }

                if (getSign.rewards[a][1] == 2) {
                    var menu = item.getChildByTag(a);
                    menu.setVisible(true);
                }
            }
        }*/
    },

    onSetSign: function (event) {
        cc.log("onSetSign");

        var setSign = event.getUserData();

        cc.log("setSign.isSign:" + setSign.isSign);
        cc.log("setSign.itemCount:" + setSign.itemCount);
//        cc.log("signRewards:"+signRewards.toString());
        switch(setSign.isSign){
        case 1: //签到成功
        	if (userInfo.isVip) {
//        		signLayer.isVIPSign.setVisible(true);
//        		signLayer.VIPSignMenu.setVisible(false);
        		cc.log("vip你妹");
        		this.signLayer && this.signLayer.showRewards(true);
        	}
        	else {
//        		signLayer.isSign.setVisible(true);
//      		signLayer.signMenu.setVisible(false);
        		this.signLayer && this.signLayer.showRewards();
        		cc.log("平民签到成功");
        	}
        	userInfo.gold = userInfo.gold + 1000;
//        	this.topLayer && this.topLayer.removeChildByTag(101);
        	this.topLayer && this.topLayer.setUserGold(userInfo.gold);
        	
        	break;
        case 2: //签到失败 已签到
        	cc.log("签到失败 已签到");
        	break;

        }
        /*switch (setSign.isSign) {
            case 1: //签到成功
                if (userInfo.isVip) {
                    signLayer.isVIPSign.setVisible(true);
                    signLayer.VIPSignMenu.setVisible(false);
                }
                else {
                    signLayer.isSign.setVisible(true);
                    signLayer.signMenu.setVisible(false);
                }

                var signCount = gpNamespace.signDays;
                signLayer.setSignCount(parseInt(signCount) + 1);
                gpNamespace.signDays = parseInt(signCount) + 1;

                if (userInfo.isVip) {
                    var currentGold = userInfo.gold;
                    var restGold = parseInt(currentGold) + 10000;
                    userInfo.gold = restGold;
                    topLayer.setUserGold(restGold);
                }

                //参赛券表现--------------------------------------------------------------
                var runningScene = cc.director.getRunningScene();
                var jumpLayer = new cc.Layer();
                runningScene.addChild(jumpLayer, 10);

                var cansai = new cc.Sprite("#mj_ty_73.png");
                cansai.attr({
                    x: 920,
                    y: 520
                });
                jumpLayer.addChild(cansai);
                cansai.setScale(0.6);

                //乘号
                var plusName = "#zuos_030u.png";
                var plus = new cc.Sprite(plusName);
                plus.attr({
                    x: 990,
                    y: 520
                });
                jumpLayer.addChild(plus);

                //数量
                var countName = "#zuos_022u.png";
                var count = new cc.Sprite(countName);
                count.attr({
                    x: 1020,
                    y: 520
                });
                jumpLayer.addChild(count);

                var isVip = userInfo.isVip;
                if (isVip) {
                    var gold = new cc.Sprite("#mj_ty_70.png");
                    gold.attr({
                        x: 920,
                        y: 560
                    });
                    jumpLayer.addChild(gold);
                    gold.setScale(0.6);

                    //乘号
                    var plusName = "#zuos_030u.png";
                    var plus = new cc.Sprite(plusName);
                    plus.attr({
                        x: 990,
                        y: 560
                    });
                    jumpLayer.addChild(plus);

                    //数量
                    var count = 10000;
                    for (var i = 0; i < count.toString().length; i++) {
                        var str = parseInt(count.toString().substr(i, 1)) + 20;
                        var spritName = "#zuos_0" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: 1020 + 24 * i,
                            y: 560
                        });
                        jumpLayer.addChild(countCell);
                    }

                    var runningScene = cc.director.getRunningScene();
                    var runningArmature = new ccs.Armature("coins");
                    runningArmature.getAnimation().playWithIndex(0);
                    runningArmature.getAnimation().setSpeedScale(1);
                    runningArmature.setScale(1);
                    runningArmature.setAnchorPoint(0.5, 0.5);
                    runningArmature.setPosition(560, 580);
                    runningScene.addChild(runningArmature, 10);
                    runningArmature.getAnimation().setMovementEventCallFunc(this.callBackRemove, runningScene);
                }

                jumpLayer.runAction(cc.sequence(cc.spawn(cc.moveBy(1.5, 0, 60), cc.fadeOut(1.5)), cc.callFunc(function () {
                    jumpLayer.removeFromParent(true);
                })));
                //-------------------------------------------------------------------------

                for (var a = 0; a < setSign.itemCount; a++) {
                    var item = signLayer.scrollview.array[a];

                    if (setSign.signRewards[a][1] == 1) {
                        var sprite = item.getChildByTag(10 + a);
                        sprite.setVisible(true);
                    }

                    if (setSign.signRewards[a][1] == 2) {
                        var sprite = item.getChildByTag(20 + a);
                        sprite.setVisible(true);
                    }

                    if (setSign.signRewards[a][1] == 1) {
                        var menu = item.getChildByTag(a);
                        menu.setVisible(false);
                    }
                }

                break;

            case 2: //签到失败 已签到
                cc.log("签到失败 已签到");
                break;

            case 3: //补签成功
                gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.HuaEffect, false);

                if (gpNamespace.vipFreeBuSign > 0) {
                    signLayer.buSignMenu.setVisible(false);
                    signLayer.vipBuSignMenu.setVisible(true);

                    gpNamespace.vipFreeBuSign--;

                    signLayer.addFreeDay(gpNamespace.vipFreeBuSign);

                    if (gpNamespace.vipFreeBuSign == 0) {
                        signLayer.buSignMenu.setVisible(true);
                        signLayer.vipBuSignMenu.setVisible(false);
                    }
                } else {
                    signLayer.buSignMenu.setVisible(true);
                    signLayer.vipBuSignMenu.setVisible(false);

                    if (signLayer.buSignCountLabel.getString() == "1") {
                        if (userInfo.isVip) {
                            signLayer.isVIPBuSign.setVisible(true);
                            signLayer.buSignMenu.setVisible(false);
                        }
                        else {
                            signLayer.isBuSign.setVisible(true);
                            signLayer.buSignMenu.setVisible(false);
                        }
                    }
                }

                var buSignCount = gpNamespace.buSignDays;
                signLayer.setBuSignCount(parseInt(buSignCount) - 1);
                gpNamespace.buSignDays = parseInt(buSignCount) - 1;

                var signCount = gpNamespace.signDays;
                signLayer.setSignCount(parseInt(signCount) + 1);
                gpNamespace.signDays = parseInt(signCount) + 1;

                if (gpNamespace.vipFreeBuSign == 0 && setSign.buSignPropCount != 0) {
                    //补签卡表现--------------------------------------------------------------
                    var runningScene = cc.director.getRunningScene();
                    var jumpLayer = new cc.Layer();
                    runningScene.addChild(jumpLayer, 10);

                    var cansai = new cc.Sprite("#mj_ty_69.png");
                    cansai.attr({
                        x: 920,
                        y: 320
                    });
                    jumpLayer.addChild(cansai);
                    cansai.setScale(0.6);

                    //乘号
                    var plusName = "#zuos_030u.png";
                    var plus = new cc.Sprite(plusName);
                    plus.attr({
                        x: 990,
                        y: 320
                    });
                    jumpLayer.addChild(plus);

                    //数量
                    var count = setSign.buSignPropCount;
                    for (var i = 0; i < count.toString().length; i++) {
                        var str = parseInt(count.toString().substr(i, 1)) + 20;
                        var spritName = "#zuos_0" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: 1020 + 24 * i,
                            y: 320
                        });
                        jumpLayer.addChild(countCell);
                    }

                    //var countName = "#zuos_021u.png";
                    //var count = new cc.Sprite(countName);
                    //count.attr({
                    //    x: 1020,
                    //    y: 320
                    //});
                    //jumpLayer.addChild(count);

                    jumpLayer.runAction(cc.sequence(cc.spawn(cc.moveBy(1.5, 0, 60), cc.fadeOut(1.5)), cc.callFunc(function () {
                        jumpLayer.removeFromParent(true);
                    })));
                    //-----------------------------------------------------------------
                }

                for (var a = 0; a < setSign.itemCount; a++) {
                    var item = signLayer.scrollview.array[a];

                    if (setSign.signRewards[a][1] == 1) {
                        var sprite = item.getChildByTag(10 + a);
                        sprite.setVisible(true);
                    }

                    if (setSign.signRewards[a][1] == 2) {
                        var sprite = item.getChildByTag(20 + a);
                        sprite.setVisible(true);
                    }

                    if (setSign.signRewards[a][1] == 1) {
                        var menu = item.getChildByTag(a);
                        menu.setVisible(false);
                    }
                }

                break;

            case 4: //补签卡不足
                cc.log("补签失败 补签卡不足");

                var runningScene = cc.director.getRunningScene();
                var tyModelLayer = new gpNamespace.TyModelLayer1();
                runningScene.addChild(tyModelLayer, 10);

                var signJumpLayer = new gpNamespace.SignJumpLayer();
                signJumpLayer.attr({
                    x: 0,
                    y: cc.winSize.height
                });
                tyModelLayer.addChild(signJumpLayer);

                signJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;
        }*/
    },

    onGetMail: function (event) {
        cc.log("onGetMail");

        var getMail = event.getUserData();
        userMailInfo = getMail;

//        var mailLayer = this.mailLayer;

        cc.log("获取到邮件mailType:" + getMail.mailType);
        cc.log("获取到邮件总数目itemCount:" + getMail.itemCount);
        for (var a = 0; a < getMail.itemCount; a++) {
            cc.log("hasAttachment:" + getMail.mails[a][0]);
            cc.log("isRead:" + getMail.mails[a][1]);
            cc.log("mailID:" + getMail.mails[a][2]);
            cc.log("senderType:" + getMail.mails[a][3]);
            cc.log("createDate:" + getMail.mails[a][4]);
            cc.log("title:" + getMail.mails[a][5]);
        }
        if(getMail.itemCount > 0){
        	this.mailLayer && this.mailLayer.setMailContainer(getMail);
        }else{
        	this.mailLayer && this.mailLayer.setNoMail();
        	this.mailLayer && this.mailLayer.sethiddle();
        }
        this.bottomLayer && this.bottomLayer.setMailTips();

    },

    mailOneCallbackFunction: function (sender) {
        cc.log("某一个邮件");

//        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

//        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        var mailLayer = this.mailLayer;

        var index = data[0];
        var tag = index + 1;
        var hasAttach = data[1];
        var mailID = data[2];
        
//        console.log("index:"+index);
//        console.log("tag:"+tag);
//        console.log("hasAttach:"+hasAttach);
//        console.log("mailID:"+mailID);

        ////右面内容初始化
        //mailLayer.senderField.setString("");
        //mailLayer.senderTitleField.setString("");
        //mailLayer.scrollview2.clearContainer();

        /*var tyNet = gpNamespace.TyNetManager.getInstance();
        if (!this.added) {
            var items = mailLayer.scrollview1.array;

            var touchItem = mailLayer.scrollview1.container.getChildByTag(tag);

            for (var a = 0; a < items.length; a++) {
                items[a].getChildByTag(1).setVisible(false);
                if (items[a] == touchItem.getChildren()[0]) {
                    items[a].getChildByTag(1).setVisible(true);
                    items[a].getChildByTag(2).setVisible(false);
                    items[a].getChildByTag(3).setVisible(false);
                    items[a].getChildByTag(4).setVisible(true);
                    items[a].getChildByTag(5).setVisible(false);
                    if (hasAttach == 1) {
                        items[a].getChildByTag(5).setVisible(true);
                    }
                }
            }

            gpNamespace.MailGetData = gpNamespace.MailReceiveData;
            gpNamespace.MailGetData[1][index][0] = 0;
            gpNamespace.MailGetData[1][index][1] = 2;

            gpNamespace.AttachmentID = gpNamespace.MailGetData[1][index][2];

            xinyou.netManager.getMailInfo(mailID);

            this.added = true;
            this.mailLayer.scheduleOnce(function () {
                tyNet.added = false;
            }, 0.2);
        }*/
    },

    deleteCallbackFunction: function (sender) {
        cc.log("删除邮件");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonClearMessage, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        var mailLayer = this.mailLayer;

        var editType = 3;
        var index = data[0];
        var tag = index + 1;
        var maidID = data[1];

        gpNamespace.MailDeleteData = [];
        gpNamespace.MailDeleteData.push(gpNamespace.MailReceiveData[1][index]);

        var item = mailLayer.scrollview1.container.getChildByTag(tag);
        var action = cc.moveBy(0.5, -410, 0);
        item.runAction(action.easing(cc.easeBackIn()));

        xinyou.netManager.mailEdit(editType, maidID);
    },

    //获取单个邮件
    onMailInfo: function (event) {
        cc.log("onMailInfo");

        var mailInfo = event.getUserData();

        this.mailLayer.setMailDetail(mailInfo);
        
//        xinyou.netManager.getGameNotice();

        cc.log("senderID:" + mailInfo.senderID);
        cc.log("isRead:" + mailInfo.isRead);
        cc.log("mailID:" + mailInfo.mailID);
        cc.log("receiverID:" + mailInfo.receiverID);
        cc.log("senderType:" + mailInfo.senderType);
        cc.log("content:" + mailInfo.content);
        cc.log("createDate:" + mailInfo.createDate);
        cc.log("senderName:" + mailInfo.senderName);
        cc.log("attachmentCount:" + mailInfo.attachmentCount);
        //for (var a = 0; a < mailInfo.attachmentCount; a++) {
        //    cc.log("attachmentID:" + mailInfo.attachments[a][0]);
        //    cc.log("attachmentQuantity:" + mailInfo.attachments[a][1]);
        //    cc.log("---------------");
        //}
        //cc.log("receiverName:" + mailInfo.receiverName);
        //cc.log("title:" + mailInfo.title);

//        mailLayer.scrollview2.clearContainer();
//        mailLayer.senderField.setString(mailInfo.senderName);
//        mailLayer.senderTitleField.setString(mailInfo.title);
//
//        var singleHeight = 30;
//        var singleLength = 28;
//
//        //内容多少行
//        var content = [];
//        var str1 = "亲爱的" + mailInfo.receiverName + "，您好:";
//        gpNamespace.TyTalkData = [];
//        var strArray = gpNamespace.GetSlicedArray("　　" + mailInfo.content, singleLength);
//        var str2 = mailInfo.createDate;
//        content.push(str1);
//        for (var a = 0; a < strArray.length; a++) {
//            content.push(strArray[a]);
//        }
//        content.push(str2);
//
//        var itemArray = [];
//
//        for (var b = 0; b < content.length; b++) {
//            itemArray[b] = new cc.Sprite(gpNamespace.ty.Ty_dot);
//
//            var item;
//            if (b == content.length - 1) {
//                item = new cc.LabelTTF(content[b], "Arial", 25);
//                item.attr({
//                    x: 40,
//                    y: -15,
//                    anchorX: 0,
//                    anchorY: 0
//                });
//            }
//            else {
//                item = new cc.LabelTTF(content[b], "Arial", 25);
//                item.attr({
//                    x: -180,
//                    y: -15,
//                    anchorX: 0,
//                    anchorY: 0
//                });
//            }
//            itemArray[b].addChild(item);
//        }
//        if (mailInfo.attachmentCount != 0) {
//            itemArray[content.length] = new cc.Sprite(gpNamespace.ty.Ty_dot);
//            var item = new cc.LabelTTF("附件：", "Arial", 25);
//            item.attr({
//                x: -180,
//                y: -15,
//                anchorX: 0,
//                anchorY: 0
//            });
//            itemArray[content.length].addChild(item);
//
//            for (var b = content.length + 1; b < (content.length + 1 + mailInfo.attachmentCount); b++) {
//                itemArray[b] = new cc.Sprite(gpNamespace.ty.Ty_dot);
//
//                //图标
//                var str = mailInfo.attachments[b - content.length - 1][0];
//                if (str > 5)
//                    str = 5;
//                var spiteName = "#zjm_yj_06" + str + "u.png";
//                var icon = new cc.Sprite(spiteName);
//                icon.attr({
//                    x: -140,
//                    y: 0
//                });
//                itemArray[b].addChild(icon);
//                var x = 30 / icon.getContentSize().width;
//                var y = 30 / icon.getContentSize().height;
//                icon.setScale(x, y);
//
//                //数量
//                var count = new cc.LabelTTF("x" + mailInfo.attachments[b - content.length - 1][1], "Arial", 25);
//                count.attr({
//                    x: -100,
//                    y: -15,
//                    anchorX: 0,
//                    anchorY: 0
//                });
//                itemArray[b].addChild(count);
//            }
//
//            //收取附件按钮
//            itemArray[content.length + 1 + mailInfo.attachmentCount] = new cc.Sprite(gpNamespace.ty.Ty_dot);
//            var getAttachmentItem = new cc.MenuItemImage(gpNamespace.mail.Mail_getAttachment, gpNamespace.mail.Mail_getAttachment, this.getAttachmentCallbackFunction, this);
//            getAttachmentItem.attr({
//                x: 123 / 2,
//                y: 48 / 2
//            });
//            var getAttachmentMenu = new gpNamespace.TyMenu(getAttachmentItem);
//            getAttachmentMenu.attr({
//                x: 40,
//                y: -15
//            });
//            getAttachmentMenu.setTouchArea(mailLayer.scrollview2.touchArea);
//            getAttachmentMenu.setTouchListener();
//            //var x = 30 / icon.getContentSize().width;
//            //getAttachmentItem.setScale(x);
//            itemArray[content.length + 1 + mailInfo.attachmentCount].addChild(getAttachmentMenu);
//        }
//        mailLayer.scrollview2.setMyContainer(itemArray, 30, 1);

        ////内容多少行
        //var row = Math.ceil((mailInfo.content.length + 2) / 14);
        //
        //if (mailInfo.attachmentCount != 0) {
        //    var itemArray = [];// 25字号，14个字
        //    for (var a = 0; a < row + 7; a++) {
        //        itemArray[a] = new cc.Sprite(gpNamespace.ty.Ty_dot);
        //
        //        var item;
        //        switch (a + 1) {
        //            case 1:
        //                item = new cc.LabelTTF("亲爱的" + mailInfo.receiverName + "，您好:", "Arial", 25);
        //                item.attr({
        //                    x: -180,
        //                    y: -15,
        //                    anchorX: 0,
        //                    anchorY: 0
        //                });
        //                break;
        //
        //            case row + 2:
        //                item = new cc.LabelTTF(mailInfo.createDate, "Arial", 25);
        //                item.attr({
        //                    x: 40,
        //                    y: -15,
        //                    anchorX: 0,
        //                    anchorY: 0
        //                });
        //                break;
        //
        //            case row + 3:
        //                item = new cc.Sprite(gpNamespace.mail.Mail_attachmentBackground);
        //                item.attr({
        //                    x: -85,
        //                    y: -30
        //                });
        //                var gold = new cc.Sprite(gpNamespace.mail.Mail_attachmentGold);
        //                gold.attr({
        //                    x: item.getContentSize().width / 2,
        //                    y: item.getContentSize().height / 2
        //                });
        //                item.addChild(gold);
        //                break;
        //
        //            case row + 4:
        //            case row + 5:
        //            case row + 7:
        //                item = new cc.LabelTTF("", "Arial", 25);
        //                break;
        //
        //            case row + 6:
        //                item = new cc.Sprite(gpNamespace.mail.Mail_getAttachment);
        //                item.attr({
        //                    x: 123 / 2 + 45,
        //                    y: 48 / 2 - 40
        //                });
        //
        //                var getAttachmentItem = new cc.MenuItemImage(gpNamespace.mail.Mail_getAttachment, gpNamespace.mail.Mail_getAttachment, this.getAttachmentCallbackFunction, this);
        //                getAttachmentItem.attr({
        //                    x: 123 / 2,
        //                    y: 48 / 2
        //                });
        //                var getAttachmentMenu = new gpNamespace.TyMenu(getAttachmentItem);
        //                getAttachmentMenu.attr({
        //                    x: 0,
        //                    y: 0
        //                });
        //                getAttachmentMenu.setTouchArea(mailLayer.scrollview2.touchArea);
        //                getAttachmentMenu.setTouchListener();
        //                item.addChild(getAttachmentMenu);
        //
        //                break;
        //
        //            default :
        //                if (a == 1)
        //                    item = new cc.LabelTTF("　　" + mailInfo.content.substr(0, Math.min(mailInfo.content.length, 12)), "Arial", 25);
        //                else if (a == row)
        //                    item = new cc.LabelTTF(mailInfo.content.substr(12 + (a - 2) * 14, (mailInfo.content.length + 2) % 14), "Arial", 25);
        //                else
        //                    item = new cc.LabelTTF(mailInfo.content.substr(12 + (a - 1) * 14, 14), "Arial", 25);
        //                item.attr({
        //                    x: -180,
        //                    y: -15,
        //                    anchorX: 0,
        //                    anchorY: 0
        //                });
        //                break;
        //        }
        //        itemArray[a].addChild(item);
        //    }
        //    mailLayer.scrollview2.setMyContainer(itemArray, 30, 1);
        //}
        //else {
        //    var itemArray = [];// 25字号，14个字
        //    for (var a = 0; a < row + 7; a++) {
        //        itemArray[a] = new cc.Sprite(gpNamespace.ty.Ty_dot);
        //
        //        var item;
        //        switch (a + 1) {
        //            case 1:
        //                item = new cc.LabelTTF("亲爱的" + mailInfo.receiverName + "，您好:", "Arial", 25);
        //                item.attr({
        //                    x: -180,
        //                    y: -15,
        //                    anchorX: 0,
        //                    anchorY: 0
        //                });
        //                break;
        //
        //            case row + 2:
        //                item = new cc.LabelTTF(mailInfo.createDate, "Arial", 25);
        //                item.attr({
        //                    x: 40,
        //                    y: -15,
        //                    anchorX: 0,
        //                    anchorY: 0
        //                });
        //                break;
        //
        //            default :
        //                if (a == 1)
        //                    item = new cc.LabelTTF("　　" + mailInfo.content.substr(0, Math.min(mailInfo.content.length, 12)), "Arial", 25);
        //                else if (a == row)
        //                    item = new cc.LabelTTF(mailInfo.content.substr(12 + (a - 2) * 14, (mailInfo.content.length + 2) % 14), "Arial", 25);
        //                else
        //                    item = new cc.LabelTTF(mailInfo.content.substr(12 + (a - 2) * 14, 14), "Arial", 25);
        //                item.attr({
        //                    x: -180,
        //                    y: -15,
        //                    anchorX: 0,
        //                    anchorY: 0
        //                });
        //                break;
        //        }
        //        itemArray[a].addChild(item);
        //    }
        //    mailLayer.scrollview2.setMyContainer(itemArray, 30, 1);
        //}
    },

    onSendMail: function (event) {
        cc.log("onSendMail");

        var sendMail = event.getUserData();

        var mailLayer = this.mailLayer;
        var topLayer = this.topLayer;

        //cc.log("result:" + sendMail.result);

        if (sendMail.result == -1) {
            gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinEffect, false);

            var currentGold = userInfo.gold;
            var sendGold = gpNamespace.sendGold;
            var restGold;
            if (sendGold == null)
                restGold = parseInt(currentGold);
            else
                restGold = parseInt(currentGold) - parseInt(sendGold);
            userInfo.gold = restGold;

            //cc.log("currentGold:" + currentGold);
            //cc.log("sendGold:" + sendGold);
            //cc.log("restGold:" + restGold);

            topLayer.setUserGold(restGold);

            mailLayer.receiverField.setVisible(false);
            mailLayer.receiverTitleField.setVisible(false);
            mailLayer.senderGoldField.setVisible(false);
            mailLayer.scrollview3.editBox.setVisible(false);

            var myNodes = [];
            myNodes.push(mailLayer.receiverField, mailLayer.receiverTitleField, mailLayer.senderGoldField, mailLayer.scrollview3.editBox);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            tyModelLayer1.setMyNodes(myNodes);
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var tyMailOKJumpLayer = new gpNamespace.TyMailOKJumpLayer();
            tyMailOKJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tyMailOKJumpLayer);
            tyMailOKJumpLayer.setParentNode(mailLayer);

            tyMailOKJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }
        if (sendMail.result == -2) {
            cc.log("只有VIP用户才能发送金币");

            mailLayer.receiverField.setVisible(false);
            mailLayer.receiverTitleField.setVisible(false);
            mailLayer.senderGoldField.setVisible(false);
            mailLayer.scrollview3.editBox.setVisible(false);

            var myNodes = [];
            myNodes.push(mailLayer.receiverField, mailLayer.receiverTitleField, mailLayer.senderGoldField, mailLayer.scrollview3.editBox);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            tyModelLayer1.setMyNodes(myNodes);
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var tyMailOnlyVIPJumpLayer = new gpNamespace.TyMailOnlyVIPJumpLayer();
            tyMailOnlyVIPJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tyMailOnlyVIPJumpLayer);
            tyMailOnlyVIPJumpLayer.setParentNode(mailLayer);

            tyMailOnlyVIPJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }
        if (sendMail.result == -3) {
            cc.log("收件人不存在");

            mailLayer.receiverField.setVisible(false);
            mailLayer.receiverTitleField.setVisible(false);
            mailLayer.senderGoldField.setVisible(false);
            mailLayer.scrollview3.editBox.setVisible(false);

            var myNodes = [];
            myNodes.push(mailLayer.receiverField, mailLayer.receiverTitleField, mailLayer.senderGoldField, mailLayer.scrollview3.editBox);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            tyModelLayer1.setMyNodes(myNodes);
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var tyMailNoReceiverJumpLayer = new gpNamespace.TyMailNoReceiverJumpLayer();
            tyMailNoReceiverJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tyMailNoReceiverJumpLayer);
            tyMailNoReceiverJumpLayer.setParentNode(mailLayer);

            tyMailNoReceiverJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }
        if (sendMail.result == -4) {
            cc.log("不能给自己发邮件");

            mailLayer.receiverField.setVisible(false);
            mailLayer.receiverTitleField.setVisible(false);
            mailLayer.senderGoldField.setVisible(false);
            mailLayer.scrollview3.editBox.setVisible(false);

            var myNodes = [];
            myNodes.push(mailLayer.receiverField, mailLayer.receiverTitleField, mailLayer.senderGoldField, mailLayer.scrollview3.editBox);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            tyModelLayer1.setMyNodes(myNodes);
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var tyMailJumpLayer = new gpNamespace.TyMailJumpLayer();
            tyMailJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tyMailJumpLayer);
            tyMailJumpLayer.setParentNode(mailLayer);

            tyMailJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }
        if (sendMail.result >= 0) {
            cc.log("今日剩余额度：" + sendMail.result);

            mailLayer.receiverField.setVisible(false);
            mailLayer.receiverTitleField.setVisible(false);
            mailLayer.senderGoldField.setVisible(false);
            mailLayer.scrollview3.editBox.setVisible(false);

            var myNodes = [];
            myNodes.push(mailLayer.receiverField, mailLayer.receiverTitleField, mailLayer.senderGoldField, mailLayer.scrollview3.editBox);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            tyModelLayer1.setMyNodes(myNodes);
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(524, 309), cc.p(378, 206));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var tyMailMoreJumpLayer = new gpNamespace.TyMailMoreJumpLayer();
            tyMailMoreJumpLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tyMailMoreJumpLayer);
            tyMailMoreJumpLayer.setParentNode(mailLayer);

            tyMailMoreJumpLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }
    },

    onMailEdit: function (event) {
        cc.log("onMailEdit");

        var mailEdit = event.getUserData();

//        var topLayer = this.topLayer;
//        var mailLayer = this.mailLayer;

        if(mailEdit.editType == 1 || mailEdit.editType == 2){
//        	cc.log("领取附件");
        	cc.log("mailEdit.result:"+mailEdit.result);//操作结果 1：成功 。 一般不会失败，二般那就不是我的事了 -_-||
//        	cc.log("editType:" + mailEdit.editType);
//        	cc.log("diamond:" + mailEdit.diamond);
//        	cc.log("voucher:" + mailEdit.voucher);
//        	cc.log("gold:" + mailEdit.gold);
//        	cc.log("cansaiquan:" + mailEdit.cansaiquan);
//      	cc.log("result:" + mailEdit.result);
        	//跳个弹窗
        	tyNamespace.tipsJumper(1,tyNamespace.TipsSectencesIndex.GetOneAttachmentSuc);

        	//先删除再设置顶部资产
//        	this.topLayer.removeChildByTag(101);
//        	this.topLayer.removeChildByTag(102);
//        	this.topLayer.removeChildByTag(103);
        	this.topLayer.setUserGold(mailEdit.gold);
        	this.topLayer.setUserDiamond(mailEdit.diamond);
        	this.topLayer.setUserVoucher(mailEdit.voucher);

        	userInfo.gold = mailEdit.gold;
        	userInfo.diamond = mailEdit.diamond;
        	userInfo.voucher = mailEdit.voucher;
        }

        /*switch (mailEdit.editType) {
            case 1: //收取附件一个
                if (mailEdit.result == 1) {
                    gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinsEffect, false);
                    gpNamespace.MailReceiveData = gpNamespace.MailGetData;
                    mailLayer.senderField.setString("");
                    mailLayer.senderTitleField.setString("");
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scrollview2.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                }
                else {
                    gpNamespace.MailGetData = [];
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                }
                break;

            case 2: //全部收取
                if (mailEdit.result == 1) {
                    gpNamespace.MailReceiveData = gpNamespace.MailGetData;
                    mailLayer.senderField.setString("");
                    mailLayer.senderTitleField.setString("");
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scrollview2.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                }
                else {
                    gpNamespace.MailGetData = [];
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                }
                break;

            case 3: //删除一个邮件
                if (mailEdit.result == 1) {
                    for (var a = 0; a < gpNamespace.MailReceiveData[1].length; a++) {
                        for (var b = 0; b < gpNamespace.MailDeleteData.length; b++) {
                            if (gpNamespace.MailDeleteData[b][2] == gpNamespace.MailReceiveData[1][a][2]) {
                                gpNamespace.MailReceiveData[1].splice(a, 1);
                            }
                        }
                    }
                    mailLayer.senderField.setString("");
                    mailLayer.senderTitleField.setString("");
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scrollview2.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                } else {
                    gpNamespace.MailDeleteData = [];
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                }
                break;

            case 4: //删除全部邮件
                if (mailEdit.result == 1) {
                    for (var a = 0; a < gpNamespace.MailReceiveData[1].length; a++) {
                        for (var b = 0; b < gpNamespace.MailDeleteData.length; b++) {
                            if (gpNamespace.MailDeleteData[b][2] == gpNamespace.MailReceiveData[1][a][2]) {
                                gpNamespace.MailReceiveData[1].splice(a, 1);
                            }
                        }
                    }
                    mailLayer.senderField.setString("");
                    mailLayer.senderTitleField.setString("");
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scrollview2.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                } else {
                    gpNamespace.MailDeleteData = [];
                    mailLayer.scrollview1.clearContainer();
                    mailLayer.scheduleOnce(this.refreshMailList, 0.2);
                }
                break;
        }*/
    },

    refreshMailList: function () {
        var mailLayer = this;

        xinyou.netManager.getGameNotice();

        if (gpNamespace.MailReceiveData[1].length == 0) {
            var noFriend = new cc.Sprite(gpNamespace.mail.Mail_noMail);
            noFriend.attr({
                x: mailLayer.scrollview1.container.getContentSize().width / 2,
                y: mailLayer.scrollview1.container.getContentSize().height - 45
            });
            mailLayer.scrollview1.container.addChild(noFriend);

            return;
        }

        if (gpNamespace.MailReceiveData[0] == 1) {
            var itemArray = [];
            for (var a = 0; a < gpNamespace.MailReceiveData[1].length; a++) {
                //背景
                if (a % 2)
                    itemArray[a] = new cc.Sprite(gpNamespace.mail.Mail_receiveBackground1);
                else
                    itemArray[a] = new cc.Sprite(gpNamespace.mail.Mail_receiveBackground2);

                //选中黄色
                var yellow = new cc.Sprite(gpNamespace.mail.Mail_receiveBackground3);
                yellow.attr({
                    x: 0,
                    y: 0,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(yellow);
                yellow.setTag(1);
                yellow.setVisible(false);

                //未读标记
                var unRead = new cc.Sprite(gpNamespace.mail.Mail_unRead);
                unRead.attr({
                    x: 11,
                    y: 18,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(unRead);
                unRead.setTag(2);
                unRead.setVisible(false);

                //未读标记1
                var unRead1 = new cc.Sprite(gpNamespace.mail.Mail_unRead1);
                unRead1.attr({
                    x: 11,
                    y: 18,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(unRead1);
                unRead1.setTag(3);
                unRead1.setVisible(false);

                //已读标记
                var read = new cc.Sprite(gpNamespace.mail.Mail_read);
                read.attr({
                    x: 11,
                    y: 14,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(read);
                read.setTag(4);
                read.setVisible(false);

                //感叹号
                var gantanhao = new cc.Sprite(gpNamespace.mail.Mail_gantanhao);
                gantanhao.attr({
                    x: 8,
                    y: 29,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(gantanhao);
                gantanhao.setTag(5);
                gantanhao.setVisible(false);

                //邮件图标 已读未读 感叹号
                switch (gpNamespace.MailReceiveData[1][a][1]) {
                    case 0://未读
                        if (gpNamespace.MailReceiveData[1][a][3] != 0) {
                            unRead.setVisible(false);
                            unRead1.setVisible(true);
                        }
                        else {
                            unRead.setVisible(true);
                            unRead1.setVisible(false);
                        }
                        read.setVisible(false);
                        gantanhao.setVisible(true);
                        break;

                    case 1://已读
                        unRead.setVisible(false);
                        unRead1.setVisible(false);
                        read.setVisible(true);
                        gantanhao.setVisible(false);
                        if (gpNamespace.MailReceiveData[1][a][0] == 1) {
                            gantanhao.setVisible(true);
                        }
                        break;

                    case 2://已领
                        unRead.setVisible(false);
                        unRead1.setVisible(false);
                        read.setVisible(true);
                        gantanhao.setVisible(false);
                        break;
                }

                //邮件标题
                var title = new cc.LabelTTF(gpNamespace.MailReceiveData[1][a][5], "Arial", 23);
                title.setFontFillColor(cc.color(120, 26, 13, 255));
                title.attr({
                    x: 100,
                    y: 42,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(title);

                //发件人类型
                var str = "";
                switch (gpNamespace.MailReceiveData[1][a][3]) {
                    case 0:
                        str = "好友消息";
                        break;
                    case 1:
                        str = "管理员消息";
                        break;
                    case 2:
                        str = "系统消息";
                        break;
                }
                var senderType = new cc.LabelTTF(str, "Arial", 20);
                senderType.setFontFillColor(cc.color(120, 26, 13, 255));
                senderType.attr({
                    x: 102,
                    y: 12,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(senderType);

                //创建时间
                var createTime = new cc.LabelTTF(gpNamespace.MailReceiveData[1][a][4].toString().slice(5), "Arial", 20);
                createTime.setFontFillColor(cc.color(120, 26, 13, 255));
                createTime.attr({
                    x: 304,
                    y: 46,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(createTime);

                var tyNet = gpNamespace.TyNetManager.getInstance();

                //某一个邮件
                var mailItem = new cc.MenuItemImage(gpNamespace.mail.Mail_mailModel, gpNamespace.mail.Mail_mailModel, tyNet.mailOneCallbackFunction, tyNet);
                mailItem.attr({
                    x: 381 / 2,
                    y: 79 / 2
                });
                mailItem.setUserData([a, gpNamespace.MailReceiveData[1][a][0], gpNamespace.MailReceiveData[1][a][2]]);
                var mailMenu = new gpNamespace.TyMenu(mailItem);
                mailMenu.attr({
                    x: 0,
                    y: 0
                });
                itemArray[a].addChild(mailMenu);
                mailMenu.setTouchArea(mailLayer.scrollview1.touchArea);

                //删除按钮
                var deleteItem = new cc.MenuItemImage(gpNamespace.mail.Mail_delete, gpNamespace.mail.Mail_delete, tyNet.deleteCallbackFunction, tyNet);
                deleteItem.attr({
                    x: 30 / 2,
                    y: 36 / 2
                });
                deleteItem.setUserData([a, gpNamespace.MailReceiveData[1][a][2]]);
                var deleteMenu = new gpNamespace.TyMenu(deleteItem);
                deleteMenu.attr({
                    x: 315,
                    y: 12
                });
                itemArray[a].addChild(deleteMenu);
                deleteMenu.setTouchArea(mailLayer.scrollview1.touchArea);
            }

            mailLayer.scrollview1.setMyContainer(itemArray, 90, 1);
        }
    },

    getAttachmentCallbackFunction: function (sender) {
        cc.log("获取附件");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        tyNamespace.setMenuEnable(sender);

        var mailID = gpNamespace.AttachmentID;
        gpNamespace.AttachmentID = "";

        xinyou.netManager.mailEdit(1, mailID);
    },

    onRank: function (event) {
        cc.log("********onRank**********");

        var rank = event.getUserData();

        var rankLayer = this.rankLayer;
        var qszbRankLayer = this.qszbRankLayer;
        var kxdzsRankLayer = this.kxdzsRankLayer;

        cc.log("收到排行榜showType:" + rank.showType);
        cc.log("收到排行榜itemCount:" + rank.itemCount);
        /*for (var a = 0; a < rank.itemCount; a++) {
            cc.log("iconID:" + rank.ranks[a][0]);
            cc.log("goodID:" + rank.ranks[a][1]);
            cc.log("rankCount:" + rank.ranks[a][2]);
            cc.log("goodCount:" + rank.ranks[a][3]);
            cc.log("currentRank:" + rank.ranks[a][4]);
            cc.log("userID:" + rank.ranks[a][5]);
            cc.log("nickName:" + rank.ranks[a][6]);
            cc.log("--------------------------");
        }*/
        
        
        
        switch (rank.showType) {
            case 1:
            	rankInfo = rank.ranks;
            	this.gpMiddleLayer&&this.gpMiddleLayer.setRankContainer(rank.ranks);
                break;

            case 2:
                var itemArray = [];
                for (var a = 0; a < rank.itemCount; a++) {
                    //背景
                    var userID = cc.sys.localStorage.getItem(gpNamespace.USER_ID_BYTE);
                    if (userID == rank.ranks[a][5]) {
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbMyItemBackground);
                    }
                    else if (a % 2)
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground1);
                    else
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground2);

                    //排名背景
                    var rankBackground;
                    switch (rank.ranks[a][4]) {
                        case 1 :
                            rankBackground = gpNamespace.rank.Rank_1;
                            break;
                        case 2 :
                            rankBackground = gpNamespace.rank.Rank_2;
                            break;
                        case 3 :
                            rankBackground = gpNamespace.rank.Rank_3;
                            break;
                        default :
                            rankBackground = gpNamespace.rank.Rank_normal;
                            break;
                    }
                    var rankBackgroundSprite = new cc.Sprite(rankBackground);
                    rankBackgroundSprite.attr({
                        x: 90,
                        y: 70
                    });
                    itemArray[a].addChild(rankBackgroundSprite);

                    //排名
                    var rankCount = rank.ranks[a][4];
                    if (rankCount > 3) {
                        for (var i = 0; i < rankCount.toString().length; i++) {
                            var str = parseInt(rankCount.toString().substr(i, 1));
                            var spritName = "#mj_qszbsz_0" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: (47.5 - rankCount.toString().length / 2 * 19) + 19 * i,
                                y: 38
                            });
                            rankBackgroundSprite.addChild(countCell);
                        }
                    }

                    //名称
                    var name = rank.ranks[a][6];
                    if (rank.ranks[a][6] == "")
                        name = "暂无";
                    var nickName = new cc.LabelTTF(name, "Arial", 28);
                    nickName.setFontFillColor(cc.color(95, 29, 0, 255));
                    nickName.attr({
                        x: 280,
                        y: 70
                    });
                    itemArray[a].addChild(nickName);

                    //积分
                    var count = rank.ranks[a][2];
                    for (var i = 0; i < count.toString().length; i++) {
                        var str = parseInt(count.toString().substr(i, 1));
                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: (540 - count.toString().length / 2 * 19) + 19 * i,
                            y: 66
                        });
                        itemArray[a].addChild(countCell);
                    }

                    if (rank.ranks[a][4] <= 30) {
                        //奖励
                        if (rank.ranks[a][1] != 1 && rank.ranks[a][1] != 2 && rank.ranks[a][1] != 3 && rank.ranks[a][1] != 4) {
                            var goodIcon;
                            if (rank.ranks[a][0] >= 5000 && rank.ranks[a][0] < 5062) {
                                //实物图标
                                var goodIconID = rank.ranks[a][0];
                                var goodIconName = "#sc_swjp_" + this.getIconName(goodIconID, 4999) + "u.png";
                                goodIcon = new cc.Sprite(goodIconName);
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                            if (rank.ranks[a][0] == 0) {
                                //实物图标
                                var goodID = rank.ranks[a][1];
                                goodIcon = new LoadHead(goodID);
                                goodIcon.loadGood();
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                        }
                        else {
                            switch (rank.ranks[a][1]) {
                                case 1://金币
                                    var spriteName = "#zjm_yj_061u.png";

                                    break;
                                case 2://钻石
                                    var spriteName = "#zjm_yj_062u.png";

                                    break;
                                case 3://兑换券
                                    var count = rank.ranks[a][3];
                                    for (var i = 0; i < count.toString().length; i++) {
                                        var str = parseInt(count.toString().substr(i, 1));
                                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                                        var countCell = new cc.Sprite(spritName);
                                        countCell.attr({
                                            x: (680 - count.toString().length / 2 * 19) + 19 * i + 45,
                                            y: 66
                                        });
                                        itemArray[a].addChild(countCell);
                                    }

                                    var spriteName = "#zjm_yj_063u.png";
                                    var sprite = new cc.Sprite(spriteName);
                                    sprite.attr({
                                        x: 775,
                                        y: 50,
                                        anchorX: 0,
                                        anchorY: 0
                                    });
                                    itemArray[a].addChild(sprite, 1);

                                    break;
                                case 4://参赛券
                                    var spriteName = "#zjm_yj_064u.png";

                                    break;
                            }
                        }
                    }
                    else {
                        var label = new cc.LabelTTF("无奖励", "Arial", 25);
                        label.setFontFillColor(cc.color(95, 29, 0, 255));
                        label.attr({
                            x: 705,
                            y: 55,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(label, 1);
                    }
                }
                qszbRankLayer.scrollview1.setMyContainer(itemArray, 148, 1);

                break;

            case 3:
                var itemArray = [];
                for (var a = 0; a < rank.itemCount; a++) {
                    //背景
                    var userID = cc.sys.localStorage.getItem(gpNamespace.USER_ID_BYTE);
                    if (userID == rank.ranks[a][5]) {
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbMyItemBackground);
                    }
                    else if (a % 2)
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground1);
                    else
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground2);

                    //排名背景
                    var rankBackground;
                    switch (rank.ranks[a][4]) {
                        case 1 :
                            rankBackground = gpNamespace.rank.Rank_1;
                            break;
                        case 2 :
                            rankBackground = gpNamespace.rank.Rank_2;
                            break;
                        case 3 :
                            rankBackground = gpNamespace.rank.Rank_3;
                            break;
                        default :
                            rankBackground = gpNamespace.rank.Rank_normal;
                            break;
                    }
                    var rankBackgroundSprite = new cc.Sprite(rankBackground);
                    rankBackgroundSprite.attr({
                        x: 90,
                        y: 70
                    });
                    itemArray[a].addChild(rankBackgroundSprite);

                    //排名
                    var rankCount = rank.ranks[a][4];
                    if (rankCount > 3) {
                        for (var i = 0; i < rankCount.toString().length; i++) {
                            var str = parseInt(rankCount.toString().substr(i, 1));
                            var spritName = "#mj_qszbsz_0" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: (47.5 - rankCount.toString().length / 2 * 19) + 19 * i,
                                y: 38
                            });
                            rankBackgroundSprite.addChild(countCell);
                        }
                    }

                    //名称
                    var name = rank.ranks[a][6];
                    if (rank.ranks[a][6] == "")
                        name = "暂无";
                    var nickName = new cc.LabelTTF(name, "Arial", 28);
                    nickName.setFontFillColor(cc.color(95, 29, 0, 255));
                    nickName.attr({
                        x: 280,
                        y: 70
                    });
                    itemArray[a].addChild(nickName);

                    //积分
                    var count = rank.ranks[a][2];
                    for (var i = 0; i < count.toString().length; i++) {
                        var str = parseInt(count.toString().substr(i, 1));
                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: (540 - count.toString().length / 2 * 19) + 19 * i,
                            y: 66
                        });
                        itemArray[a].addChild(countCell);
                    }

                    if (rank.ranks[a][4] <= 30) {
                        //奖励
                        if (rank.ranks[a][1] != 1 && rank.ranks[a][1] != 2 && rank.ranks[a][1] != 3 && rank.ranks[a][1] != 4) {
                            var goodIcon;
                            if (rank.ranks[a][0] >= 5000 && rank.ranks[a][0] < 5062) {
                                //实物图标
                                var goodIconID = rank.ranks[a][0];
                                var goodIconName = "#sc_swjp_" + this.getIconName(goodIconID, 4999) + "u.png";
                                goodIcon = new cc.Sprite(goodIconName);
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                            if (rank.ranks[a][0] == 0) {
                                //实物图标
                                var goodID = rank.ranks[a][1];
                                goodIcon = new LoadHead(goodID);
                                goodIcon.loadGood();
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                        }
                        else {
                            switch (rank.ranks[a][1]) {
                                case 1://金币
                                    var spriteName = "#zjm_yj_061u.png";

                                    break;
                                case 2://钻石
                                    var spriteName = "#zjm_yj_062u.png";

                                    break;
                                case 3://兑换券
                                    var count = rank.ranks[a][3];
                                    for (var i = 0; i < count.toString().length; i++) {
                                        var str = parseInt(count.toString().substr(i, 1));
                                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                                        var countCell = new cc.Sprite(spritName);
                                        countCell.attr({
                                            x: (680 - count.toString().length / 2 * 19) + 19 * i + 45,
                                            y: 66
                                        });
                                        itemArray[a].addChild(countCell);
                                    }

                                    var spriteName = "#zjm_yj_063u.png";
                                    var sprite = new cc.Sprite(spriteName);
                                    sprite.attr({
                                        x: 780,
                                        y: 50,
                                        anchorX: 0,
                                        anchorY: 0
                                    });
                                    itemArray[a].addChild(sprite, 1);

                                    break;
                                case 4://参赛券
                                    var spriteName = "#zjm_yj_064u.png";

                                    break;
                            }
                        }

                    }
                    else {
                        var label = new cc.LabelTTF("无奖励", "Arial", 25);
                        label.setFontFillColor(cc.color(95, 29, 0, 255));
                        label.attr({
                            x: 705,
                            y: 55,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(label, 1);
                    }
                }
                kxdzsRankLayer.scrollview1.setMyContainer(itemArray, 148, 1);

                break;

            case 4:
                var itemArray = [];
                var myRankPosition = 0;
                for (var a = 0; a < rank.itemCount; a++) {
                    //背景
                    var userID = cc.sys.localStorage.getItem(gpNamespace.USER_ID_BYTE);

                    if (userID == rank.ranks[a][5]) {
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_myItemBackground);
                        myRankPosition = a;
                    }
                    else if (a % 2)
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_itemBackground1);
                    else
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_itemBackground2);

                    //排名背景
                    var rankBackground;
                    switch (rank.ranks[a][4]) {
                        case 1 :
                            rankBackground = gpNamespace.rank.Rank_1;
                            break;
                        case 2 :
                            rankBackground = gpNamespace.rank.Rank_2;
                            break;
                        case 3 :
                            rankBackground = gpNamespace.rank.Rank_3;
                            break;
                        default :
                            rankBackground = gpNamespace.rank.Rank_normal;
                            break;
                    }
                    var rankBackgroundSprite = new cc.Sprite(rankBackground);
                    rankBackgroundSprite.attr({
                        x: 90,
                        y: 55
                    });
                    itemArray[a].addChild(rankBackgroundSprite);

                    //排名
                    var rankCount = rank.ranks[a][4];
                    if (rankCount > 3) {
                        for (var i = 0; i < rankCount.toString().length; i++) {
                            var str = parseInt(rankCount.toString().substr(i, 1));
                            var spritName = "#mj_qszbsz_0" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            if (rankCount.toString().length < 3) {
                                countCell.attr({
                                    x: (47.5 - rankCount.toString().length / 2 * 19) + 19 * i,
                                    y: 38
                                });
                            }
                            if (rankCount.toString().length == 3) {
                                countCell.attr({
                                    x: (45 - rankCount.toString().length / 2 * 15) + 15 * i,
                                    y: 38
                                });
                                countCell.setScale(0.9);
                            }
                            if (rankCount.toString().length == 4) {
                                countCell.attr({
                                    x: (45 - rankCount.toString().length / 2 * 13) + 13 * i,
                                    y: 38
                                });
                                countCell.setScale(0.8);
                            }
                            rankBackgroundSprite.addChild(countCell);
                        }
                    }

                    //名称
                    var nickName = new cc.LabelTTF(rank.ranks[a][6], "Arial", 28);
                    nickName.setFontFillColor(cc.color(95, 29, 0, 255));
                    nickName.attr({
                        x: 335,
                        y: 55
                    });
                    itemArray[a].addChild(nickName);

                    //排名的物品数量  mj_qszbsz_00u.png
                    var rankCount = rank.ranks[a][2];
                    for (var i = 0; i < rankCount.toString().length; i++) {
                        var str = parseInt(rankCount.toString().substr(i, 1));
                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: (680 - rankCount.toString().length / 2 * 19) + 19 * i,
                            y: 55
                        });
                        itemArray[a].addChild(countCell);
                    }
                }
                rankLayer.scrollview2.setMyContainer(itemArray, 120, 1);

                if (rank.itemCount - myRankPosition > 4) {
                    rankLayer.myIndex = myRankPosition + 4;
                    rankLayer.schedule(rankLayer.toMyCallbackFunction);
                }
                else {
                    rankLayer.myIndex = rank.itemCount;
                    rankLayer.schedule(rankLayer.toMy2CallbackFunction);
                }

                break;

            case 5:
                var itemArray = [];
                var myRankPosition = 0;
                for (var a = 0; a < rank.itemCount; a++) {
                    //背景
                    var userID = cc.sys.localStorage.getItem(gpNamespace.USER_ID_BYTE);
                    if (userID == rank.ranks[a][5]) {
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbMyItemBackground);
                        myRankPosition = a;
                    }
                    else if (a % 2)
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground1);
                    else
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground2);

                    //排名背景
                    var rankBackground;
                    switch (rank.ranks[a][4]) {
                        case 1 :
                            rankBackground = gpNamespace.rank.Rank_1;
                            break;
                        case 2 :
                            rankBackground = gpNamespace.rank.Rank_2;
                            break;
                        case 3 :
                            rankBackground = gpNamespace.rank.Rank_3;
                            break;
                        default :
                            rankBackground = gpNamespace.rank.Rank_normal;
                            break;
                    }
                    var rankBackgroundSprite = new cc.Sprite(rankBackground);
                    rankBackgroundSprite.attr({
                        x: 90,
                        y: 70
                    });
                    itemArray[a].addChild(rankBackgroundSprite);

                    //排名
                    var rankCount = rank.ranks[a][4];
                    if (rankCount > 3) {
                        for (var i = 0; i < rankCount.toString().length; i++) {
                            var str = parseInt(rankCount.toString().substr(i, 1));
                            var spritName = "#mj_qszbsz_0" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: (47.5 - rankCount.toString().length / 2 * 19) + 19 * i,
                                y: 38
                            });
                            rankBackgroundSprite.addChild(countCell);
                        }
                    }

                    //名称
                    var nickName = new cc.LabelTTF(rank.ranks[a][6], "Arial", 28);
                    nickName.setFontFillColor(cc.color(95, 29, 0, 255));
                    nickName.attr({
                        x: 280,
                        y: 70
                    });
                    itemArray[a].addChild(nickName);

                    //积分
                    var count = rank.ranks[a][2];
                    for (var i = 0; i < count.toString().length; i++) {
                        var str = parseInt(count.toString().substr(i, 1));
                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: (540 - count.toString().length / 2 * 19) + 19 * i,
                            y: 66
                        });
                        itemArray[a].addChild(countCell);
                    }

                    //奖励
                    if (rank.ranks[a][4] <= 30) {
                        if (rank.ranks[a][1] != 1 && rank.ranks[a][1] != 2 && rank.ranks[a][1] != 3 && rank.ranks[a][1] != 4) {
                            var goodIcon;
                            if (rank.ranks[a][0] >= 5000 && rank.ranks[a][0] < 5062) {
                                //实物图标
                                var goodIconID = rank.ranks[a][0];
                                var goodIconName = "#sc_swjp_" + this.getIconName(goodIconID, 4999) + "u.png";
                                goodIcon = new cc.Sprite(goodIconName);
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                            if (rank.ranks[a][0] == 0) {
                                //实物图标
                                var goodID = rank.ranks[a][1];
                                goodIcon = new LoadHead(goodID);
                                goodIcon.loadGood();
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                        }
                        else {
                            switch (rank.ranks[a][1]) {
                                case 1://金币
                                    var spriteName = "#zjm_yj_061u.png";

                                    break;
                                case 2://钻石
                                    var spriteName = "#zjm_yj_062u.png";

                                    break;
                                case 3://兑换券
                                    var count = rank.ranks[a][3];
                                    for (var i = 0; i < count.toString().length; i++) {
                                        var str = parseInt(count.toString().substr(i, 1));
                                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                                        var countCell = new cc.Sprite(spritName);
                                        countCell.attr({
                                            x: (680 - count.toString().length / 2 * 19) + 19 * i + 45,
                                            y: 66
                                        });
                                        itemArray[a].addChild(countCell);
                                    }

                                    var spriteName = "#zjm_yj_063u.png";
                                    var sprite = new cc.Sprite(spriteName);
                                    sprite.attr({
                                        x: 780,
                                        y: 50,
                                        anchorX: 0,
                                        anchorY: 0
                                    });
                                    itemArray[a].addChild(sprite, 1);

                                    break;
                                case 4://参赛券
                                    var spriteName = "#zjm_yj_064u.png";

                                    break;
                            }
                        }
                    }
                    else {
                        var label = new cc.LabelTTF("无奖励", "Arial", 25);
                        label.setFontFillColor(cc.color(95, 29, 0, 255));
                        label.attr({
                            x: 705,
                            y: 55,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(label, 1);
                    }
                }
                qszbRankLayer.scrollview2.setMyContainer(itemArray, 148, 1);

                if (rank.itemCount - myRankPosition > 4) {
                    qszbRankLayer.myIndex = myRankPosition + 4;
                    qszbRankLayer.schedule(qszbRankLayer.toMyCallbackFunction);
                }
                else {
                    qszbRankLayer.myIndex = rank.itemCount;
                    qszbRankLayer.schedule(qszbRankLayer.toMy2CallbackFunction);
                }

                break;

            case 6:
                var itemArray = [];
                var myRankPosition = 0;
                for (var a = 0; a < rank.itemCount; a++) {
                    //背景
                    var userID = cc.sys.localStorage.getItem(gpNamespace.USER_ID_BYTE);
                    if (userID == rank.ranks[a][5]) {
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbMyItemBackground);
                        myRankPosition = a;
                    }
                    else if (a % 2)
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground1);
                    else
                        itemArray[a] = new cc.Sprite(gpNamespace.rank.Rank_qszbItemBackground2);

                    //排名背景
                    var rankBackground;
                    switch (rank.ranks[a][4]) {
                        case 1 :
                            rankBackground = gpNamespace.rank.Rank_1;
                            break;
                        case 2 :
                            rankBackground = gpNamespace.rank.Rank_2;
                            break;
                        case 3 :
                            rankBackground = gpNamespace.rank.Rank_3;
                            break;
                        default :
                            rankBackground = gpNamespace.rank.Rank_normal;
                            break;
                    }
                    var rankBackgroundSprite = new cc.Sprite(rankBackground);
                    rankBackgroundSprite.attr({
                        x: 90,
                        y: 70
                    });
                    itemArray[a].addChild(rankBackgroundSprite);

                    //排名
                    var rankCount = rank.ranks[a][4];
                    if (rankCount > 3) {
                        for (var i = 0; i < rankCount.toString().length; i++) {
                            var str = parseInt(rankCount.toString().substr(i, 1));
                            var spritName = "#mj_qszbsz_0" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: (47.5 - rankCount.toString().length / 2 * 19) + 19 * i,
                                y: 38
                            });
                            rankBackgroundSprite.addChild(countCell);
                        }
                    }

                    //名称
                    var nickName = new cc.LabelTTF(rank.ranks[a][6], "Arial", 28);
                    nickName.setFontFillColor(cc.color(95, 29, 0, 255));
                    nickName.attr({
                        x: 280,
                        y: 70
                    });
                    itemArray[a].addChild(nickName);

                    //积分
                    var count = rank.ranks[a][2];
                    for (var i = 0; i < count.toString().length; i++) {
                        var str = parseInt(count.toString().substr(i, 1));
                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: (540 - count.toString().length / 2 * 19) + 19 * i,
                            y: 66
                        });
                        itemArray[a].addChild(countCell);
                    }

                    //奖励
                    if (rank.ranks[a][4] <= 30) {
                        if (rank.ranks[a][1] != 1 && rank.ranks[a][1] != 2 && rank.ranks[a][1] != 3 && rank.ranks[a][1] != 4) {
                            var goodIcon;
                            if (rank.ranks[a][0] >= 5000 && rank.ranks[a][0] < 5062) {
                                //实物图标
                                var goodIconID = rank.ranks[a][0];
                                var goodIconName = "#sc_swjp_" + this.getIconName(goodIconID, 4999) + "u.png";
                                goodIcon = new cc.Sprite(goodIconName);
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                            if (rank.ranks[a][0] == 0) {
                                //实物图标
                                var goodID = rank.ranks[a][1];
                                goodIcon = new LoadHead(goodID);
                                goodIcon.loadGood();
                                goodIcon.attr({
                                    x: 750,
                                    y: 65
                                });
                                //goodIcon.setScale(0.5);
                                itemArray[a].addChild(goodIcon, 1);
                            }
                        }
                        else {
                            switch (rank.ranks[a][1]) {
                                case 1://金币
                                    var spriteName = "#zjm_yj_061u.png";

                                    break;
                                case 2://钻石
                                    var spriteName = "#zjm_yj_062u.png";

                                    break;
                                case 3://兑换券
                                    var count = rank.ranks[a][3];
                                    for (var i = 0; i < count.toString().length; i++) {
                                        var str = parseInt(count.toString().substr(i, 1));
                                        var spritName = "#mj_qszbsz_0" + str + "u.png";
                                        var countCell = new cc.Sprite(spritName);
                                        countCell.attr({
                                            x: (680 - count.toString().length / 2 * 19) + 19 * i + 45,
                                            y: 66
                                        });
                                        itemArray[a].addChild(countCell);
                                    }

                                    var spriteName = "#zjm_yj_063u.png";
                                    var sprite = new cc.Sprite(spriteName);
                                    sprite.attr({
                                        x: 780,
                                        y: 50,
                                        anchorX: 0,
                                        anchorY: 0
                                    });
                                    itemArray[a].addChild(sprite, 1);

                                    break;
                                case 4://参赛券
                                    var spriteName = "#zjm_yj_064u.png";

                                    break;
                            }
                        }
                    }
                    else {
                        var label = new cc.LabelTTF("无奖励", "Arial", 25);
                        label.setFontFillColor(cc.color(95, 29, 0, 255));
                        label.attr({
                            x: 705,
                            y: 55,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(label, 1);
                    }
                }
                kxdzsRankLayer.scrollview2.setMyContainer(itemArray, 148, 1);

                if (rank.itemCount - myRankPosition > 4) {
                    kxdzsRankLayer.myIndex = myRankPosition + 4;
                    kxdzsRankLayer.schedule(kxdzsRankLayer.toMyCallbackFunction);
                }
                else {
                    kxdzsRankLayer.myIndex = rank.itemCount;
                    kxdzsRankLayer.schedule(kxdzsRankLayer.toMy2CallbackFunction);
                }

                break;

            default:
                if (rank.itemCount == null) {
                    var runningScene = cc.director.getRunningScene();
                    var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                    tyJumpLayerWithText.setLabelText("没有您的排名！");
                    runningScene.addChild(tyJumpLayerWithText, 10);
                }
                break;
        }
    },

    onMission: function (event) {
        cc.log("onMission");

        var mission = event.getUserData();

        var missionLayer = this.missionLayer;

        var gameLayer = this.gameLayer;

        //cc.log("missionType:" + mission.missionType);
        //cc.log("roomType:" + mission.roomType);
        //cc.log("missionLevel:" + mission.missionLevel);
        //cc.log("itemCount:" + mission.itemCount);
        //for (var a = 0; a < mission.itemCount; a++) {
        //    cc.log("missionIconID:" + mission.missions[a][0]);
        //    cc.log("missionID:" + mission.missions[a][1]);
        //    cc.log("missionTimes:" + mission.missions[a][2]);
        //    cc.log("userTimes:" + mission.missions[a][3]);
        //    cc.log("rewardItemCount:" + mission.missions[a][4]);
        //    for (var b = 0; b < mission.missions[a][4] / 2; b++) {
        //        cc.log("rewardID:" + mission.missions[a][5][b][0]);
        //        cc.log("rewardCount:" + mission.missions[a][5][b][1]);
        //        cc.log("-------------里-------------");
        //    }
        //    cc.log("missionName:" + mission.missions[a][6]);
        //    cc.log("------------外--------------");
        //}//missionID上面加了一个missionIconID字段

        //内部任务本地保存
        if (mission.missionType == 2) {
            gpNamespace.InnerMissionData = [];
            gpNamespace.InnerMissionData[0] = mission.missionType;              //missionType          2：游戏中任务  3：大厅任务  4:VIP任务
            gpNamespace.InnerMissionData[1] = mission.roomType;                 //roomType             0：麻将  1：斗地主 2：德州扑克 3：大厅
            gpNamespace.InnerMissionData[2] = mission.missionLevel;             //missionLevel         0：外部任务 1：初级  2：中级   3：高级   4：大师
            gpNamespace.InnerMissionData[3] = [];
            for (var a = 0; a < mission.itemCount; a++) {
                gpNamespace.InnerMissionData[3][a] = [];
                gpNamespace.InnerMissionData[3][a][0] = mission.missions[a][0];        //missionIconID        任务图标id
                gpNamespace.InnerMissionData[3][a][1] = mission.missions[a][1];        //missionID            任务id
                gpNamespace.InnerMissionData[3][a][2] = mission.missions[a][2];        //missionTimes         任务总次数
                gpNamespace.InnerMissionData[3][a][3] = mission.missions[a][3];        //userTimes            玩家完成次数
                gpNamespace.InnerMissionData[3][a][4] = [];
                for (var b = 0; b < mission.missions[a][4] / 2; b++) {
                    gpNamespace.InnerMissionData[3][a][4][b] = [];
                    gpNamespace.InnerMissionData[3][a][4][b][0] = mission.missions[a][5][b][0];        //rewardID            任务奖励id   1:金币 2:钻石 3:兑换券 4:参赛券
                    gpNamespace.InnerMissionData[3][a][4][b][1] = mission.missions[a][5][b][1];        //rewardCount         任务奖励数量
                }
                gpNamespace.InnerMissionData[3][a][5] = mission.missions[a][6];        //missionName          任务名字
            }
        }

        //外部普通任务本地保存
        if (mission.missionType == 3) {
            gpNamespace.MissionData = [];
            gpNamespace.MissionData[0] = mission.missionType;              //missionType          2：游戏中任务  3：大厅任务  4:VIP任务
            gpNamespace.MissionData[1] = mission.roomType;                 //roomType             0：麻将  1：斗地主 2：德州扑克 3：大厅
            gpNamespace.MissionData[2] = mission.missionLevel;             //missionLevel         0：外部任务 1：初级  2：中级   3：高级   4：大师
            gpNamespace.MissionData[3] = [];
            for (var a = 0; a < mission.itemCount; a++) {
                gpNamespace.MissionData[3][a] = [];
                gpNamespace.MissionData[3][a][0] = mission.missions[a][0];        //missionIconID        任务图标id
                gpNamespace.MissionData[3][a][1] = mission.missions[a][1];        //missionID            任务id
                gpNamespace.MissionData[3][a][2] = mission.missions[a][2];        //missionTimes         任务总次数
                gpNamespace.MissionData[3][a][3] = mission.missions[a][3];        //userTimes            玩家完成次数
                gpNamespace.MissionData[3][a][4] = [];
                for (var b = 0; b < mission.missions[a][4] / 2; b++) {
                    gpNamespace.MissionData[3][a][4][b] = [];
                    gpNamespace.MissionData[3][a][4][b][0] = mission.missions[a][5][b][0];        //rewardID            任务奖励id   1:金币 2:钻石 3:兑换券
                    gpNamespace.MissionData[3][a][4][b][1] = mission.missions[a][5][b][1];        //rewardCount         任务奖励数量
                }
                gpNamespace.MissionData[3][a][5] = mission.missions[a][6];        //missionName          任务名字
            }
        }

        //内部任务
        if (mission.missionType == 2) {
            switch (mission.roomType) {
                case 0: //麻将任务
                    for (var a = 0; a < mission.itemCount; a++) {
                        for (var i = mission.missions[a][3].toString().length, j = 0; i > 0; i--, j++) {
                            var str = mission.missions[a][3].toString().substr(i - 1, 1);
                            var spritName = "#zuos_00" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: 134 - 12 * j,
                                y: 118 - 32 * a,
                                anchorX: 0,
                                anchorY: 0
                            });
                            countCell.setTag(10);
                            gameLayer.missionSprite.addChild(countCell);
                        }

                        var xiegang = new cc.Sprite("#zuos_010u.png");
                        xiegang.attr({
                            x: 146,
                            y: 118 - 32 * a,
                            anchorX: 0,
                            anchorY: 0
                        });
                        xiegang.setTag(10);
                        gameLayer.missionSprite.addChild(xiegang);

                        for (var i = 0; i < mission.missions[a][2].toString().length; i++) {
                            var str = parseInt(mission.missions[a][2].toString().substr(i, 1));
                            var spritName = "#zuos_00" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: 154 + 12 * i,
                                y: 118 - 32 * a,
                                anchorX: 0,
                                anchorY: 0
                            });
                            countCell.setTag(10);
                            gameLayer.missionSprite.addChild(countCell);
                        }

                        if (a != 3) {
                            for (var i = 0; i < mission.missions[a][5][0][1].toString().length; i++) {
                                var str = parseInt(mission.missions[a][5][0][1].toString().substr(i, 1));
                                var spritName = "#zuos_00" + str + "u.png";
                                var countCell = new cc.Sprite(spritName);
                                countCell.attr({
                                    x: 237 + 12 * i,
                                    y: 118 - 32 * a,
                                    anchorX: 0,
                                    anchorY: 0
                                });
                                countCell.setTag(10);
                                gameLayer.missionSprite.addChild(countCell);
                            }
                        }
                    }

                    break;

                case 1: //斗地主任务
                    for (var a = 0; a < mission.itemCount; a++) {
                        for (var i = mission.missions[a][3].toString().length, j = 0; i > 0; i--, j++) {
                            var str = mission.missions[a][3].toString().substr(i - 1, 1);
                            var spritName = "#zuos_00" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: 134 - 12 * j,
                                y: 118 - 32 * a,
                                anchorX: 0,
                                anchorY: 0
                            });
                            countCell.setTag(10);
                            gameLayer.missionSprite.addChild(countCell);
                        }

                        var xiegang = new cc.Sprite("#zuos_010u.png");
                        xiegang.attr({
                            x: 146,
                            y: 118 - 32 * a,
                            anchorX: 0,
                            anchorY: 0
                        });
                        xiegang.setTag(10);
                        gameLayer.missionSprite.addChild(xiegang);

                        for (var i = 0; i < mission.missions[a][2].toString().length; i++) {
                            var str = parseInt(mission.missions[a][2].toString().substr(i, 1));
                            var spritName = "#zuos_00" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: 154 + 12 * i,
                                y: 118 - 32 * a,
                                anchorX: 0,
                                anchorY: 0
                            });
                            countCell.setTag(10);
                            gameLayer.missionSprite.addChild(countCell);
                        }

                        if (a != 3) {
                            for (var i = 0; i < mission.missions[a][5][0][1].toString().length; i++) {
                                var str = parseInt(mission.missions[a][5][0][1].toString().substr(i, 1));
                                var spritName = "#zuos_00" + str + "u.png";
                                var countCell = new cc.Sprite(spritName);
                                countCell.attr({
                                    x: 237 + 12 * i,
                                    y: 118 - 32 * a,
                                    anchorX: 0,
                                    anchorY: 0
                                });
                                countCell.setTag(10);
                                gameLayer.missionSprite.addChild(countCell);
                            }
                        }
                    }

                    break;
            }
        }

        //外部普通任务
        if (mission.missionType == 3) {
            switch (mission.roomType) {
                case 0: //麻将任务
                    var itemArray = [];
                    for (var a = 0; a < mission.itemCount; a++) {
                        itemArray[a] = new cc.Sprite(gpNamespace.mission.Mission_missionBackground);

                        //任务图标背景
                        var itemBackground = new cc.Sprite(gpNamespace.mission.Mission_itemBackground);
                        itemBackground.attr({
                            x: 20,
                            y: 23,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(itemBackground);

                        //任务图标
                        var goodIcon;
                        if (mission.missions[a][0] >= 6000 && mission.missions[a][0] < 6058) {
                            //实物图标
                            var goodIconID = mission.missions[a][0];
                            var goodIconName = "#zjm_rwtb_" + this.getIconName(goodIconID, 5999) + ".png";
                            goodIcon = new cc.Sprite(goodIconName);
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }
                        if (mission.missions[a][0] == 0) {
                            //实物图标
                            var goodID = mission.missions[a][1];
                            goodIcon = new LoadHead(goodID);
                            goodIcon.loadGood();
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }

                        //任务名字label
                        var missionNameLabel = new cc.LabelTTF(mission.missions[a][6], "Arial", 32);
                        missionNameLabel.attr({
                            x: 162,
                            y: 100,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionNameLabel);

                        //任务进度label
                        var missionProgressLabel = new cc.LabelTTF("进度：", "Arial", 30);
                        missionProgressLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionProgressLabel.attr({
                            x: 162,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionProgressLabel);

                        //任务进度label1
                        var missionProgressLabel1 = new cc.LabelTTF(mission.missions[a][3].toString() + " / " + mission.missions[a][2].toString(), "Arial", 24);
                        missionProgressLabel1.setFontFillColor(cc.color(255, 255, 255, 255));
                        missionProgressLabel1.attr({
                            x: 330,
                            y: 65
                        });
                        itemArray[a].addChild(missionProgressLabel1);

                        //进度条背景
                        var progressBackground = new cc.Sprite(gpNamespace.mission.Mission_progressBackground);
                        progressBackground.attr({
                            x: 250,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(progressBackground);

                        //进度条
                        var progressSprite = new cc.Sprite(gpNamespace.mission.Mission_progress);
                        var progress = new cc.ProgressTimer(progressSprite);
                        progress.attr({
                            x: 254,
                            y: 19,
                            anchorX: 0,
                            anchorY: 0
                        });
                        progress.setBarChangeRate(cc.p(1, 0));
                        progress.setMidpoint(cc.p(0, 0.5));
                        progress.setType(cc.ProgressTimer.TYPE_BAR);
                        progress.setPercentage(mission.missions[a][3] / mission.missions[a][2] * 100);
                        itemArray[a].addChild(progress);

                        //任务奖励label
                        var missionJiangliLabel = new cc.LabelTTF("奖励：", "Arial", 30);
                        missionJiangliLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionJiangliLabel.attr({
                            x: 436,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionJiangliLabel);

                        //任务奖励数字label
                        var str = "";
                        switch (mission.missions[a][5][0][0]) {
                            case 1: //金币
                                str = "金币";
                                break;

                            case 2: //钻石
                                str = "钻石";
                                break;

                            case 3: //兑换券
                                str = "兑换券";
                                break;
                        }

                        var jiangliCountLabel = new cc.LabelTTF(mission.missions[a][5][0][1].toString() + str, "Arial", 30);
                        jiangliCountLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        jiangliCountLabel.attr({
                            x: 520,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(jiangliCountLabel);

                        //任务按钮
                        var missionButtonItem = new cc.MenuItemImage(gpNamespace.mission.Mission_button2, gpNamespace.mission.Mission_button2, this.missionButtonFunction, this);
                        missionButtonItem.attr({
                            x: 163 / 2,
                            y: 59 / 2
                        });
                        missionButtonItem.setUserData([mission.missions[a][1], mission.roomType]);
                        var missionButtonMenu = new gpNamespace.TyMenu(missionButtonItem);
                        missionButtonMenu.attr({
                            x: 695,
                            y: 45
                        });
                        itemArray[a].addChild(missionButtonMenu);
                        missionButtonMenu.setTouchArea(missionLayer.scrollview.touchArea);
                        missionButtonMenu.setVisible(false);

                        //不能领取的情况1
                        var missionButtonSprite1 = new cc.Sprite(gpNamespace.mission.Mission_button2);
                        missionButtonSprite1.attr({
                            x: 695,
                            y: 45,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionButtonSprite1);
                        missionButtonSprite1.setVisible(false);

                        //不能领取的情况2
                        var missionButtonSprite2 = new cc.Sprite(gpNamespace.mission.Mission_button1);
                        missionButtonSprite2.attr({
                            x: 695,
                            y: 45,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionButtonSprite2);
                        missionButtonSprite2.setVisible(false);

                        //设置按钮状况
                        if (mission.missions[a][3] >= mission.missions[a][2]) {
                            missionButtonMenu.setVisible(true);
                            missionButtonSprite1.setVisible(false);
                            missionButtonSprite2.setVisible(false);
                        }
                        else {
                            missionButtonMenu.setVisible(false);
                            missionButtonSprite1.setVisible(true);
                            missionButtonSprite2.setVisible(true);
                        }
                    }

                    missionLayer.scrollview.setMyContainer(itemArray, 165, 1);

                    break;

                case 1: //斗地主任务
                    var itemArray = [];
                    for (var a = 0; a < mission.itemCount; a++) {
                        itemArray[a] = new cc.Sprite(gpNamespace.mission.Mission_missionBackground);

                        //任务图标背景
                        var itemBackground = new cc.Sprite(gpNamespace.mission.Mission_itemBackground);
                        itemBackground.attr({
                            x: 20,
                            y: 23,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(itemBackground);

                        //任务图标
                        var goodIcon;
                        if (mission.missions[a][0] >= 6000 && mission.missions[a][0] < 6061) {
                            //实物图标
                            var goodIconID = mission.missions[a][0];
                            var goodIconName = "#zjm_rwtb_" + (this.getIconName(goodIconID, 5999)) + ".png";
                            goodIcon = new cc.Sprite(goodIconName);
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }
                        if (mission.missions[a][0] == 0) {
                            //实物图标
                            var goodID = mission.missions[a][1];
                            goodIcon = new LoadHead(goodID);
                            goodIcon.loadGood();
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }

                        //任务名字label
                        var missionNameLabel = new cc.LabelTTF(mission.missions[a][6], "Arial", 32);
                        missionNameLabel.attr({
                            x: 162,
                            y: 100,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionNameLabel);

                        //任务进度label
                        var missionProgressLabel = new cc.LabelTTF("进度：", "Arial", 30);
                        missionProgressLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionProgressLabel.attr({
                            x: 162,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionProgressLabel);

                        //任务进度label1
                        var missionProgressLabel1 = new cc.LabelTTF(mission.missions[a][3].toString() + " / " + mission.missions[a][2].toString(), "Arial", 24);
                        missionProgressLabel1.setFontFillColor(cc.color(255, 255, 255, 255));
                        missionProgressLabel1.attr({
                            x: 330,
                            y: 65
                        });
                        itemArray[a].addChild(missionProgressLabel1);

                        //进度条背景
                        var progressBackground = new cc.Sprite(gpNamespace.mission.Mission_progressBackground);
                        progressBackground.attr({
                            x: 250,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(progressBackground);

                        //进度条
                        var progressSprite = new cc.Sprite(gpNamespace.mission.Mission_progress);
                        var progress = new cc.ProgressTimer(progressSprite);
                        progress.attr({
                            x: 254,
                            y: 19,
                            anchorX: 0,
                            anchorY: 0
                        });
                        progress.setBarChangeRate(cc.p(1, 0));
                        progress.setMidpoint(cc.p(0, 0.5));
                        progress.setType(cc.ProgressTimer.TYPE_BAR);
                        progress.setPercentage(mission.missions[a][3] / mission.missions[a][2] * 100);
                        itemArray[a].addChild(progress);

                        //任务奖励label
                        var missionJiangliLabel = new cc.LabelTTF("奖励：", "Arial", 30);
                        missionJiangliLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionJiangliLabel.attr({
                            x: 436,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionJiangliLabel);

                        //任务奖励数字label
                        var str = "";
                        switch (mission.missions[a][5][0][0]) {
                            case 1: //金币
                                str = "金币";
                                break;

                            case 2: //钻石
                                str = "钻石";
                                break;

                            case 3: //兑换券
                                str = "兑换券";
                                break;
                        }

                        var jiangliCountLabel = new cc.LabelTTF(mission.missions[a][5][0][1].toString() + str, "Arial", 30);
                        jiangliCountLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        jiangliCountLabel.attr({
                            x: 520,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(jiangliCountLabel);

                        //任务按钮
                        var missionButtonItem = new cc.MenuItemImage(gpNamespace.mission.Mission_button2, gpNamespace.mission.Mission_button2, this.missionButtonFunction, this);
                        missionButtonItem.attr({
                            x: 163 / 2,
                            y: 59 / 2
                        });
                        missionButtonItem.setUserData([mission.missions[a][1], mission.roomType]);
                        var missionButtonMenu = new gpNamespace.TyMenu(missionButtonItem);
                        missionButtonMenu.attr({
                            x: 695,
                            y: 45
                        });
                        itemArray[a].addChild(missionButtonMenu);
                        missionButtonMenu.setTouchArea(missionLayer.scrollview.touchArea);
                        missionButtonMenu.setVisible(false);

                        //不能领取的情况1
                        var missionButtonSprite1 = new cc.Sprite(gpNamespace.mission.Mission_button2);
                        missionButtonSprite1.attr({
                            x: 695,
                            y: 45,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionButtonSprite1);
                        missionButtonSprite1.setVisible(false);

                        //不能领取的情况2
                        var missionButtonSprite2 = new cc.Sprite(gpNamespace.mission.Mission_button1);
                        missionButtonSprite2.attr({
                            x: 695,
                            y: 45,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionButtonSprite2);
                        missionButtonSprite2.setVisible(false);

                        //设置按钮状况
                        if (mission.missions[a][3] >= mission.missions[a][2]) {
                            missionButtonMenu.setVisible(true);
                            missionButtonSprite1.setVisible(false);
                            missionButtonSprite2.setVisible(false);
                        }
                        else {
                            missionButtonMenu.setVisible(false);
                            missionButtonSprite1.setVisible(true);
                            missionButtonSprite2.setVisible(true);
                        }
                    }

                    missionLayer.scrollview.setMyContainer(itemArray, 165, 1);

                    break;
            }
        }

        //外部VIP任务
        if (mission.missionType == 4) {
            switch (mission.roomType) {
                case 0: //麻将任务
                    var itemArray = [];
                    for (var a = 0; a < mission.itemCount; a++) {
                        itemArray[a] = new cc.Sprite(gpNamespace.mission.Mission_missionBackground1);

                        //任务图标背景
                        var itemBackground = new cc.Sprite(gpNamespace.mission.Mission_itemBackground);
                        itemBackground.attr({
                            x: 20,
                            y: 23,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(itemBackground);

                        //任务图标
                        var goodIcon;
                        if (mission.missions[a][0] >= 6000 && mission.missions[a][0] < 6058) {
                            //实物图标
                            var goodIconID = mission.missions[a][0];
                            var goodIconName = "#zjm_rwtb_" + this.getIconName(goodIconID, 5999) + ".png";
                            goodIcon = new cc.Sprite(goodIconName);
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }
                        if (mission.missions[a][0] == 0) {
                            //实物图标
                            var goodID = mission.missions[a][1];
                            goodIcon = new LoadHead(goodID);
                            goodIcon.loadGood();
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }

                        //任务名字label
                        var missionNameLabel = new cc.LabelTTF(mission.missions[a][6], "Arial", 32);
                        missionNameLabel.attr({
                            x: 162,
                            y: 100,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionNameLabel);

                        //任务进度label
                        var missionProgressLabel = new cc.LabelTTF("进度：", "Arial", 30);
                        missionProgressLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionProgressLabel.attr({
                            x: 162,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionProgressLabel);

                        //任务进度label1
                        var missionProgressLabel1 = new cc.LabelTTF(mission.missions[a][3].toString() + " / " + mission.missions[a][2].toString(), "Arial", 24);
                        missionProgressLabel1.setFontFillColor(cc.color(255, 255, 255, 255));
                        missionProgressLabel1.attr({
                            x: 330,
                            y: 65
                        });
                        itemArray[a].addChild(missionProgressLabel1);

                        //进度条背景
                        var progressBackground = new cc.Sprite(gpNamespace.mission.Mission_progressBackground);
                        progressBackground.attr({
                            x: 250,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(progressBackground);

                        //进度条
                        var progressSprite = new cc.Sprite(gpNamespace.mission.Mission_progress);
                        var progress = new cc.ProgressTimer(progressSprite);
                        progress.attr({
                            x: 254,
                            y: 19,
                            anchorX: 0,
                            anchorY: 0
                        });
                        progress.setBarChangeRate(cc.p(1, 0));
                        progress.setMidpoint(cc.p(0, 0.5));
                        progress.setType(cc.ProgressTimer.TYPE_BAR);
                        progress.setPercentage(mission.missions[a][3] / mission.missions[a][2] * 100);
                        itemArray[a].addChild(progress);

                        //任务奖励label
                        var missionJiangliLabel = new cc.LabelTTF("奖励：", "Arial", 30);
                        missionJiangliLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionJiangliLabel.attr({
                            x: 436,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionJiangliLabel);

                        //任务奖励数字label
                        var str = "";
                        switch (mission.missions[a][5][0][0]) {
                            case 1: //金币
                                str = "金币";
                                break;

                            case 2: //钻石
                                str = "钻石";
                                break;

                            case 3: //兑换券
                                str = "兑换券";
                                break;
                        }

                        var jiangliCountLabel = new cc.LabelTTF(mission.missions[a][5][0][1].toString() + str, "Arial", 30);
                        jiangliCountLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        jiangliCountLabel.attr({
                            x: 520,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(jiangliCountLabel);

                        //tag
                        var vipTag = new cc.Sprite(gpNamespace.mission.Mission_vip);
                        vipTag.attr({
                            x: 718,
                            y: 10,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(vipTag);
                    }
                    missionLayer.scrollview1.setMyContainer(itemArray, 165, 1);

                    break;

                case 1: //斗地主任务
                    var itemArray = [];
                    for (var a = 0; a < mission.itemCount; a++) {
                        itemArray[a] = new cc.Sprite(gpNamespace.mission.Mission_missionBackground1);

                        //任务图标背景
                        var itemBackground = new cc.Sprite(gpNamespace.mission.Mission_itemBackground);
                        itemBackground.attr({
                            x: 20,
                            y: 23,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(itemBackground);

                        //任务图标
                        var goodIcon;
                        if (mission.missions[a][0] >= 6000 && mission.missions[a][0] < 6061) {
                            //实物图标
                            var goodIconID = mission.missions[a][0];
                            var goodIconName = "#zjm_rwtb_" + this.getIconName(goodIconID, 5999) + ".png";
                            goodIcon = new cc.Sprite(goodIconName);
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }
                        if (mission.missions[a][0] == 0) {
                            //实物图标
                            var goodID = mission.missions[a][1];
                            goodIcon = new LoadHead(goodID);
                            goodIcon.loadGood();
                            goodIcon.attr({
                                x: itemBackground.getContentSize().width / 2,
                                y: itemBackground.getContentSize().height / 2
                            });
                            itemBackground.addChild(goodIcon);
                        }

                        //任务名字label
                        var missionNameLabel = new cc.LabelTTF(mission.missions[a][6], "Arial", 32);
                        missionNameLabel.attr({
                            x: 162,
                            y: 100,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionNameLabel);

                        //任务进度label
                        var missionProgressLabel = new cc.LabelTTF("进度：", "Arial", 30);
                        missionProgressLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionProgressLabel.attr({
                            x: 162,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionProgressLabel);

                        //任务进度label1
                        var missionProgressLabel1 = new cc.LabelTTF(mission.missions[a][3].toString() + " / " + mission.missions[a][2].toString(), "Arial", 24);
                        missionProgressLabel1.setFontFillColor(cc.color(255, 255, 255, 255));
                        missionProgressLabel1.attr({
                            x: 330,
                            y: 65
                        });
                        itemArray[a].addChild(missionProgressLabel1);

                        //进度条背景
                        var progressBackground = new cc.Sprite(gpNamespace.mission.Mission_progressBackground);
                        progressBackground.attr({
                            x: 250,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(progressBackground);

                        //进度条
                        var progressSprite = new cc.Sprite(gpNamespace.mission.Mission_progress);
                        var progress = new cc.ProgressTimer(progressSprite);
                        progress.attr({
                            x: 254,
                            y: 19,
                            anchorX: 0,
                            anchorY: 0
                        });
                        progress.setBarChangeRate(cc.p(1, 0));
                        progress.setMidpoint(cc.p(0, 0.5));
                        progress.setType(cc.ProgressTimer.TYPE_BAR);
                        progress.setPercentage(mission.missions[a][3] / mission.missions[a][2] * 100);
                        itemArray[a].addChild(progress);

                        //任务奖励label
                        var missionJiangliLabel = new cc.LabelTTF("奖励：", "Arial", 30);
                        missionJiangliLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        missionJiangliLabel.attr({
                            x: 436,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(missionJiangliLabel);

                        //任务奖励数字label
                        var str = "";
                        switch (mission.missions[a][5][0][0]) {
                            case 1: //金币
                                str = "金币";
                                break;

                            case 2: //钻石
                                str = "钻石";
                                break;

                            case 3: //兑换券
                                str = "兑换券";
                                break;
                        }

                        var jiangliCountLabel = new cc.LabelTTF(mission.missions[a][5][0][1].toString() + str, "Arial", 30);
                        jiangliCountLabel.setFontFillColor(cc.color(195, 40, 31, 255));
                        jiangliCountLabel.attr({
                            x: 520,
                            y: 20,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(jiangliCountLabel);

                        //tag
                        var vipTag = new cc.Sprite(gpNamespace.mission.Mission_vip);
                        vipTag.attr({
                            x: 718,
                            y: 10,
                            anchorX: 0,
                            anchorY: 0
                        });
                        itemArray[a].addChild(vipTag);
                    }
                    missionLayer.scrollview1.setMyContainer(itemArray, 165, 1);

                    break;
            }
        }
    },

    onInnerMission: function (event) {
        cc.log("onInnerMission");

        var innerMission = event.getUserData();

        this.innerMissionRewardTimes++;

        var runningScene = cc.director.getRunningScene();
        var missionRewardLayer = new cc.Layer();
        runningScene.addChild(missionRewardLayer, 10);

        //cc.log("innerMission.diamond:" + innerMission.diamond);
        //cc.log("innerMission.entryTicket:" + innerMission.entryTicket);
        //cc.log("innerMission.voucher:" + innerMission.voucher);
        //cc.log("innerMission.gold:" + innerMission.gold);
        //cc.log("innerMission.isVIP:" + innerMission.isVIP);
        //cc.log("innerMission.result:" + innerMission.result);
        //cc.log("innerMission.missionID:" + innerMission.missionID);

        //userInfo.gold = innerMission.gold;    //若内部任务有金币需要打开
        userInfo.diamond = innerMission.diamond;
        userInfo.voucher = innerMission.voucher;

        for (var a = 0; a < gpNamespace.InnerMissionData[3].length; a++) {
            if (innerMission.missionID == gpNamespace.InnerMissionData[3][a][1])
                gpNamespace.InnerMissionData[3][a][3] = parseInt(gpNamespace.InnerMissionData[3][a][3]) + 1;

            if (innerMission.result == 1 && gpNamespace.InnerMissionData[3][a][3] == gpNamespace.InnerMissionData[3][a][2]) {
                cc.log("跳奖励");

                gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.InnerMissionOK, false);

                if (innerMission.isVIP) {
                    var vipSprite = new cc.Sprite("#mj_yxjx_0024u.png");
                    vipSprite.attr({
                        x: 250,
                        y: 300 + 10 * this.innerMissionRewardTimes
                    });
                    missionRewardLayer.addChild(vipSprite);
                }

                //奖励种类
                var spriteName = "#mj_yxjx_0005u.png";
                if (gpNamespace.InnerMissionData[3][a][4][0][0] == 4)
                    spriteName = "#mj_yxjx_0004u.png";
                var sprite = new cc.Sprite(spriteName);
                sprite.attr({
                    x: 200,
                    y: 290 + 10 * this.innerMissionRewardTimes
                });
                missionRewardLayer.addChild(sprite, 1);
                sprite.setScale(0.6);

                //乘号
                var plusName = "#zuos_030u.png";
                var plus = new cc.Sprite(plusName);
                plus.attr({
                    x: 270,
                    y: 290 + 10 * this.innerMissionRewardTimes
                });
                missionRewardLayer.addChild(plus, 1);

                //数量
                var str = gpNamespace.subRoom + 20;
                var countName = "#zuos_0" + str + "u.png";
                var count = new cc.Sprite(countName);
                count.attr({
                    x: 300,
                    y: 290 + 10 * this.innerMissionRewardTimes
                });
                missionRewardLayer.addChild(count, 1);

                missionRewardLayer.runAction(cc.sequence(cc.spawn(cc.moveBy(1.5, 0, 60), cc.fadeOut(1.5)), cc.callFunc(function () {
                    missionRewardLayer.removeFromParent(true);
                })));
            }

            this.refreshInnerMission();
        }
    },

    refreshInnerMission: function () {
        cc.log("刷新内部任务");

        var gameLayer = this.gameLayer;

        gameLayer.missionSprite.removeAllChildren();

        //麻将
        if (gpNamespace.InnerMissionData[1] == 0) {
            //四个麻将任务
            var mj1 = new cc.Sprite("#mj_yxjx_0016u.png");
            mj1.attr({
                x: 5,
                y: 116,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj1);

            var mj2 = new cc.Sprite("#mj_yxjx_0018u.png");
            mj2.attr({
                x: 5,
                y: 85,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj2);

            var mj3 = new cc.Sprite("#mj_yxjx_0022u.png");
            mj3.attr({
                x: 5,
                y: 52,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj3);

            var mj4 = new cc.Sprite("#mj_yxjx_0014u.png");
            mj4.attr({
                x: 5,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj4);
        }

        //斗地主
        if (gpNamespace.InnerMissionData[1] == 1) {
            //四个斗地主任务
            var mj1 = new cc.Sprite("#mj_yxjx_0016u.png");
            mj1.attr({
                x: 5,
                y: 116,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj1);

            var mj2 = new cc.Sprite("#mj_yxjx_0010u.png");
            mj2.attr({
                x: 5,
                y: 85,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj2);

            var mj3 = new cc.Sprite("#mj_yxjx_0020u.png");
            mj3.attr({
                x: 5,
                y: 52,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj3);

            var mj4 = new cc.Sprite("#mj_yxjx_0014u.png");
            mj4.attr({
                x: 5,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            gameLayer.missionSprite.addChild(mj4);
        }

        switch (gpNamespace.InnerMissionData[1]) {
            case 0: //麻将任务
                for (var a = 0; a < gpNamespace.InnerMissionData[3].length; a++) {
                    for (var i = gpNamespace.InnerMissionData[3][a][3].toString().length, j = 0; i > 0; i--, j++) {
                        var str = gpNamespace.InnerMissionData[3][a][3].toString().substr(i - 1, 1);
                        var spritName = "#zuos_00" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: 134 - 12 * j,
                            y: 118 - 32 * a,
                            anchorX: 0,
                            anchorY: 0
                        });
                        gameLayer.missionSprite.addChild(countCell);
                    }

                    var xiegang = new cc.Sprite("#zuos_010u.png");
                    xiegang.attr({
                        x: 146,
                        y: 118 - 32 * a,
                        anchorX: 0,
                        anchorY: 0
                    });
                    gameLayer.missionSprite.addChild(xiegang);

                    for (var i = 0; i < gpNamespace.InnerMissionData[3][a][2].toString().length; i++) {
                        var str = parseInt(gpNamespace.InnerMissionData[3][a][2].toString().substr(i, 1));
                        var spritName = "#zuos_00" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: 154 + 12 * i,
                            y: 118 - 32 * a,
                            anchorX: 0,
                            anchorY: 0
                        });
                        gameLayer.missionSprite.addChild(countCell);
                    }

                    if (a != 3) {
                        for (var i = 0; i < gpNamespace.InnerMissionData[3][a][4][0][1].toString().length; i++) {
                            var str = parseInt(gpNamespace.InnerMissionData[3][a][4][0][1].toString().substr(i, 1));
                            var spritName = "#zuos_00" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: 237 + 12 * i,
                                y: 118 - 32 * a,
                                anchorX: 0,
                                anchorY: 0
                            });
                            gameLayer.missionSprite.addChild(countCell);
                        }
                    }
                }

                break;

            case 1: //斗地主任务
                for (var a = 0; a < gpNamespace.InnerMissionData[3].length; a++) {
                    for (var i = gpNamespace.InnerMissionData[3][a][3].toString().length, j = 0; i > 0; i--, j++) {
                        var str = gpNamespace.InnerMissionData[3][a][3].toString().substr(i - 1, 1);
                        var spritName = "#zuos_00" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: 134 - 12 * j,
                            y: 118 - 32 * a,
                            anchorX: 0,
                            anchorY: 0
                        });
                        gameLayer.missionSprite.addChild(countCell);
                    }

                    var xiegang = new cc.Sprite("#zuos_010u.png");
                    xiegang.attr({
                        x: 146,
                        y: 118 - 32 * a,
                        anchorX: 0,
                        anchorY: 0
                    });
                    gameLayer.missionSprite.addChild(xiegang);

                    for (var i = 0; i < gpNamespace.InnerMissionData[3][a][2].toString().length; i++) {
                        var str = parseInt(gpNamespace.InnerMissionData[3][a][2].toString().substr(i, 1));
                        var spritName = "#zuos_00" + str + "u.png";
                        var countCell = new cc.Sprite(spritName);
                        countCell.attr({
                            x: 154 + 12 * i,
                            y: 118 - 32 * a,
                            anchorX: 0,
                            anchorY: 0
                        });
                        gameLayer.missionSprite.addChild(countCell);
                    }

                    if (a != 3) {
                        for (var i = 0; i < gpNamespace.InnerMissionData[3][a][4][0][1].toString().length; i++) {
                            var str = parseInt(gpNamespace.InnerMissionData[3][a][4][0][1].toString().substr(i, 1));
                            var spritName = "#zuos_00" + str + "u.png";
                            var countCell = new cc.Sprite(spritName);
                            countCell.attr({
                                x: 237 + 12 * i,
                                y: 118 - 32 * a,
                                anchorX: 0,
                                anchorY: 0
                            });
                            gameLayer.missionSprite.addChild(countCell);
                        }
                    }
                }

                break;
        }
    },

    onMissionReward: function (event) {
        cc.log("onMissionReward");

        var missionReward = event.getUserData();

        var missionLayer = this.missionLayer;

        xinyou.netManager.getGameNotice();

        if (missionReward.result != 1)
            return;

        //cc.log("roomType:" + missionReward.roomType);
        //cc.log("diamond:" + missionReward.diamond);
        //cc.log("voucher:" + missionReward.voucher);
        //cc.log("gold:" + missionReward.gold);
        //cc.log("result:" + missionReward.result);
        //cc.log("missionID:" + missionReward.missionID);
        //cc.log("missionTimes:" + missionReward.missionTimes);
        //cc.log("userTimes:" + missionReward.userTimes);
        //cc.log("rewardItemCount:" + missionReward.rewardItemCount);
        //for (var a = 0; a < missionReward.rewardItemCount / 2; b++) {
        //    cc.log("rewardID:" + missionReward.rewards[a][0]);
        //    cc.log("rewardCount:" + missionReward.rewards[a][1]);
        //}
        //cc.log("missionName:" + missionReward.missionName);

        //修改本地任务记录
        for (var a = 0; a < gpNamespace.MissionData[3].length; a++) {
            if (gpNamespace.MissionData[3][a][1] == missionReward.missionID) {
                gpNamespace.MissionData[3][a][0] = missionReward.missionIconID;
                gpNamespace.MissionData[3][a][2] = missionReward.missionTimes;
                gpNamespace.MissionData[3][a][3] = missionReward.userTimes;
                for (var b = 0; b < gpNamespace.MissionData[3][a][3].length; b++) {
                    gpNamespace.MissionData[3][a][4][b][0] = missionReward.rewards[b][0];
                    gpNamespace.MissionData[3][a][4][b][1] = missionReward.rewards[b][1];
                }
                gpNamespace.MissionData[3][a][5] = missionReward.missionName;
            }
        }

        //重新排列本地任务列表
        var localMissions = gpNamespace.MissionData[3];
        localMissions.sort(function (a, b) {
            return a[3] / a[2] < b[3] / b[2] ? 1 : -1
        });

        //cc.log("missionType:" + gpNamespace.MissionData[0]);
        //cc.log("roomType:" + gpNamespace.MissionData[1]);
        //cc.log("missionLevel:" + gpNamespace.MissionData[2]);
        //for (var a = 0; a < gpNamespace.MissionData[3].length; a++) {
        //    cc.log("missionID:" + gpNamespace.MissionData[3][a][0]);
        //    cc.log("missionTimes:" + gpNamespace.MissionData[3][a][1]);
        //    cc.log("userTimes:" + gpNamespace.MissionData[3][a][2]);
        //for (var b = 0; b < gpNamespace.MissionData[3][a][3].length; b++) {
        //    cc.log("rewardID:" + gpNamespace.MissionData[3][a][3][b][0]);
        //    cc.log("rewardCount:" + gpNamespace.MissionData[3][a][3][b][1]);
        //}
        //cc.log("missionName:" + gpNamespace.MissionData[3][a][4]);
        //}

        if (cc.sys.isObjectValid(this.topLayer)) {
            this.topLayer.setUserGold(missionReward.gold);
            this.topLayer.setUserDiamond(missionReward.diamond);
            this.topLayer.setUserDui(missionReward.voucher);
        }

        userInfo.gold = missionReward.gold;
        userInfo.diamond = missionReward.diamond;
        userInfo.voucher = missionReward.voucher;

        missionLayer.scrollview.clearContainer();

        var itemArray = [];
        for (var a = 0; a < gpNamespace.MissionData[3].length; a++) {
            itemArray[a] = new cc.Sprite(gpNamespace.mission.Mission_missionBackground);

            //任务图标背景
            var itemBackground = new cc.Sprite(gpNamespace.mission.Mission_itemBackground);
            itemBackground.attr({
                x: 20,
                y: 26,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(itemBackground);

            //任务图标
            var goodIcon;
            if (gpNamespace.MissionData[3][a][0] >= 6000 && gpNamespace.MissionData[3][a][0] < 6058) {
                //实物图标
                var goodIconID = gpNamespace.MissionData[3][a][0];
                var goodIconName = "#zjm_rwtb_" + this.getIconName(goodIconID, 5999) + ".png";
                goodIcon = new cc.Sprite(goodIconName);
                goodIcon.attr({
                    x: itemBackground.getContentSize().width / 2,
                    y: itemBackground.getContentSize().height / 2
                });
                itemBackground.addChild(goodIcon);
            }
            if (gpNamespace.MissionData[3][a][0] >= 6058 && gpNamespace.MissionData[3][a][0] < 7000) {
                //实物图标
                var goodID = gpNamespace.MissionData[3][a][0];
                goodIcon = new LoadHead(goodID);
                goodIcon.loadGood();
                goodIcon.attr({
                    x: itemBackground.getContentSize().width / 2,
                    y: itemBackground.getContentSize().height / 2
                });
                itemBackground.addChild(goodIcon);
            }

            //任务名字label
            var missionNameLabel = new cc.LabelTTF(gpNamespace.MissionData[3][a][5], "Arial", 32);
            missionNameLabel.attr({
                x: 162,
                y: 100,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(missionNameLabel);

            //任务进度label
            var missionProgressLabel = new cc.LabelTTF("进度：", "Arial", 30);
            missionProgressLabel.setFontFillColor(cc.color(195, 40, 31, 255));
            missionProgressLabel.attr({
                x: 162,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(missionProgressLabel);

            //任务进度label1
            var missionProgressLabel1 = new cc.LabelTTF(gpNamespace.MissionData[3][a][3].toString() + " / " + gpNamespace.MissionData[3][a][2].toString(), "Arial", 24);
            missionProgressLabel1.setFontFillColor(cc.color(255, 255, 255, 255));
            missionProgressLabel1.attr({
                x: 330,
                y: 65
            });
            itemArray[a].addChild(missionProgressLabel1);

            //进度条背景
            var progressBackground = new cc.Sprite(gpNamespace.mission.Mission_progressBackground);
            progressBackground.attr({
                x: 250,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(progressBackground);

            //进度条
            var progressSprite = new cc.Sprite(gpNamespace.mission.Mission_progress);
            var progress = new cc.ProgressTimer(progressSprite);
            progress.attr({
                x: 254,
                y: 19,
                anchorX: 0,
                anchorY: 0
            });
            progress.setBarChangeRate(cc.p(1, 0));
            progress.setMidpoint(cc.p(0, 0.5));
            progress.setType(cc.ProgressTimer.TYPE_BAR);
            progress.setPercentage(gpNamespace.MissionData[3][a][3] / gpNamespace.MissionData[3][a][2] * 100);
            itemArray[a].addChild(progress);

            //任务奖励label
            var missionJiangliLabel = new cc.LabelTTF("奖励：", "Arial", 30);
            missionJiangliLabel.setFontFillColor(cc.color(195, 40, 31, 255));
            missionJiangliLabel.attr({
                x: 436,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(missionJiangliLabel);

            //任务奖励数字label
            var jiangliCountLabel = new cc.LabelTTF(gpNamespace.MissionData[3][a][4][0][1].toString(), "Arial", 30);
            jiangliCountLabel.setFontFillColor(cc.color(195, 40, 31, 255));
            jiangliCountLabel.attr({
                x: 520,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(jiangliCountLabel);

            //任务按钮
            var missionButtonItem = new cc.MenuItemImage(gpNamespace.mission.Mission_button2, gpNamespace.mission.Mission_button2, this.missionButtonFunction, this);
            missionButtonItem.attr({
                x: 163 / 2,
                y: 59 / 2
            });
            missionButtonItem.setUserData([gpNamespace.MissionData[3][a][1], gpNamespace.MissionData[1]]);
            var missionButtonMenu = new gpNamespace.TyMenu(missionButtonItem);
            missionButtonMenu.attr({
                x: 695,
                y: 45
            });
            itemArray[a].addChild(missionButtonMenu);
            missionButtonMenu.setTouchArea(missionLayer.scrollview.touchArea);
            missionButtonMenu.setVisible(false);

            //不能领取的情况1
            var missionButtonSprite1 = new cc.Sprite(gpNamespace.mission.Mission_button2);
            missionButtonSprite1.attr({
                x: 695,
                y: 45,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(missionButtonSprite1);
            missionButtonSprite1.setVisible(false);

            //不能领取的情况2
            var missionButtonSprite2 = new cc.Sprite(gpNamespace.mission.Mission_button1);
            missionButtonSprite2.attr({
                x: 695,
                y: 45,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(missionButtonSprite2);
            missionButtonSprite2.setVisible(false);

            //设置按钮状况
            if (gpNamespace.MissionData[3][a][3] >= gpNamespace.MissionData[3][a][2]) {
                missionButtonMenu.setVisible(true);
                missionButtonSprite1.setVisible(false);
                missionButtonSprite2.setVisible(false);
            }
            else {
                missionButtonMenu.setVisible(false);
                missionButtonSprite1.setVisible(true);
                missionButtonSprite2.setVisible(true);
            }
        }

        missionLayer.scrollview.setMyContainer(itemArray, 165, 1);
    },

    missionButtonFunction: function (sender) {
        cc.log("领取任务按钮");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonGetMission, false);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinEffect, false);

        var data = sender.getUserData();

        var id = data[0];
        var roomType = data[1];

        xinyou.netManager.missionReward(id, roomType);
    },

    onGameMissionReward: function (event) {
        cc.log("onGameMissionReward");

        var gameMission = event.getUserData();

        var gameLayer = this.gameLayer;

        //cc.log("diamond:" + gameMission.diamond);
        //cc.log("voucher:" + gameMission.voucher);
        //cc.log("gold:" + gameMission.gold);
        //cc.log("result:" + gameMission.result);
        //cc.log("missionID:" + gameMission.missionID);

        this.topLayer && this.topLayer.setUserGold(gameMission.gold);
        this.topLayer && this.topLayer.setUserDiamond(gameMission.diamond);
        this.topLayer && this.topLayer.setUserDui(gameMission.voucher);

        //userInfo.gold = gameMission.gold; //若内部任务有金币需要打开
        userInfo.diamond = gameMission.diamond;
        userInfo.voucher = gameMission.voucher;
    },

    onFriend: function (event) {
        cc.log("onFriend");

        var friend = event.getUserData();

        cc.log("itemCount:" + friend.itemCount);
        for (var a = 0; a < friend.itemCount; a++) {
            cc.log("diamond:" + friend.friends[a][0]);
            cc.log("voucher:" + friend.friends[a][1]);
            cc.log("friendID:" + friend.friends[a][2]);
            cc.log("gold:" + friend.friends[a][3]);
            cc.log("headImageID:" + friend.friends[a][4]);
            cc.log("gender:" + friend.friends[a][5]);
            cc.log("headImagePath:" + friend.friends[a][6]);
            cc.log("nickName:" + friend.friends[a][7]);
            cc.log("--------------------------");
        }

        /*gpNamespace.TyFriendData = [];
        for (var a = 0; a < friend.itemCount; a++) {
            gpNamespace.TyFriendData[a] = [];
            gpNamespace.TyFriendData[a][0] = friend.friends[a][0];        //diamond         钻石
            gpNamespace.TyFriendData[a][1] = friend.friends[a][1];        //voucher         兑换券
            gpNamespace.TyFriendData[a][2] = friend.friends[a][2];        //friendID        好友ID
            gpNamespace.TyFriendData[a][3] = friend.friends[a][3];        //gold            金币
            gpNamespace.TyFriendData[a][4] = friend.friends[a][4];        //headImageID     头像ID
            gpNamespace.TyFriendData[a][5] = friend.friends[a][5];        //gender          性别
            gpNamespace.TyFriendData[a][6] = friend.friends[a][6];        //headImagePath   头像icon路径
            gpNamespace.TyFriendData[a][7] = friend.friends[a][7];        //nickName        昵称
        }

        var friendLayer = this.friendLayer;
        var mailLayer = this.mailLayer;

        if (friendLayer) {
            if (friend.itemCount == 0) {
                var noFriend = new cc.Sprite(gpNamespace.sj.Sj_noFriend);
                noFriend.attr({
                    x: friendLayer.scrollview1.container.getContentSize().width / 2,
                    y: friendLayer.scrollview1.container.getContentSize().height - 50
                });
                friendLayer.scrollview1.container.addChild(noFriend);
            }

            var itemArray = [];
            for (var a = 0; a < friend.itemCount; a++) {
                //背景
                if (a % 2)
                    itemArray[a] = new cc.Sprite(gpNamespace.sj.Sj_friendBackground1);
                else
                    itemArray[a] = new cc.Sprite(gpNamespace.sj.Sj_friendBackground2);

                //选中黄色
                var yellow = new cc.Sprite(gpNamespace.sj.Sj_yellow);
                yellow.attr({
                    x: 0,
                    y: 0,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(yellow);
                yellow.setTag(1);
                yellow.setVisible(false);

                //好友头像背景
                var friendHeadBackground = new cc.Sprite(gpNamespace.sj.Sj_friendHeadBackground1);
                if (friend.friends[a][5] == "女") {
                    friendHeadBackground = new cc.Sprite(gpNamespace.sj.Sj_friendHeadBackground2);
                }
                friendHeadBackground.attr({
                    x: 10,
                    y: 1,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(friendHeadBackground);

                //头像
                var headID = friend.friends[a][4];
                var img = new LoadHead(headID);
                img.loadImg();
                img.setScaleX(0.6);
                img.setScaleY(0.5);
                img.setPosition(friendHeadBackground.getContentSize().width / 2, friendHeadBackground.getContentSize().height / 2);
                friendHeadBackground.addChild(img);

                //好友头像边框
                var friendHeadBorder = new cc.Sprite(gpNamespace.sj.Sj_friendHeadBorder);
                friendHeadBorder.attr({
                    x: 0,
                    y: 0,
                    anchorX: 0,
                    anchorY: 0
                });
                friendHeadBackground.addChild(friendHeadBorder);

                //昵称label
                var nickNameLabel = new cc.LabelTTF("昵称：", "Arial", 20);
                nickNameLabel.setFontFillColor(cc.color(108, 28, 11, 255));
                nickNameLabel.attr({
                    x: 96,
                    y: 56,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(nickNameLabel);

                //昵称
                var nickName = new cc.LabelTTF(friend.friends[a][7], "Arial", 21);
                nickName.setFontFillColor(cc.color(108, 28, 11, 255));
                nickName.attr({
                    x: 156,
                    y: 56,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(nickName);

                //ID label
                var IDLabel = new cc.LabelTTF("ID：", "Arial", 21);
                IDLabel.setFontFillColor(cc.color(108, 28, 11, 255));
                IDLabel.attr({
                    x: 96,
                    y: 22,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(IDLabel);

                //ID
                var ID = new cc.LabelTTF(friend.friends[a][2].toString(), "Arial", 21);
                ID.setFontFillColor(cc.color(108, 28, 11, 255));
                ID.attr({
                    x: 130,
                    y: 22,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(ID);

                //好友条
                var friendItem = new cc.MenuItemImage(gpNamespace.sj.Sj_model, gpNamespace.sj.Sj_model, this.friendOneCallbackFunction, this);
                friendItem.attr({
                    x: 260 / 2,
                    y: 90 / 2
                });
                friendItem.setUserData([a]);
                var friendMenu = new gpNamespace.TyMenu(friendItem);
                friendMenu.attr({
                    x: 0,
                    y: 0
                });
                itemArray[a].addChild(friendMenu);
                friendMenu.setTouchArea(friendLayer.scrollview1.touchArea);

                //头部点击按钮
                var headItem = new cc.MenuItemImage(gpNamespace.sj.Sj_modelHead, gpNamespace.sj.Sj_modelHead, this.headCallbackFunction, this);
                headItem.attr({
                    x: 85 / 2,
                    y: 90 / 2
                });
                headItem.setUserData([a]);
                var headMenu = new gpNamespace.TyMenu(headItem);
                headMenu.attr({
                    x: 0,
                    y: 0
                });
                itemArray[a].addChild(headMenu);
                headMenu.setTouchArea(friendLayer.scrollview1.touchArea);

                //聊天
                var talkItem = new cc.MenuItemImage(gpNamespace.sj.Sj_talk, gpNamespace.sj.Sj_talk, this.talkCallbackFunction, this);
                talkItem.attr({
                    x: 66 / 2,
                    y: 53 / 2
                });
                talkItem.setUserData([a, friend.friends[a][7]]);
                var talkMenu = new gpNamespace.TyMenu(talkItem);
                talkMenu.attr({
                    x: 265,
                    y: 19
                });
                itemArray[a].addChild(talkMenu);
                talkMenu.setTouchArea(friendLayer.scrollview1.touchArea);
            }

            friendLayer.scrollview1.setMyContainer(itemArray, 100, 1);
        }

        if (mailLayer) {
            var itemArray = [];
            for (var a = 0; a < gpNamespace.TyFriendData.length; a++) {
                //背景
                if (a % 2)
                    itemArray[a] = new cc.Sprite(gpNamespace.mail.Mail_itemBackground2);
                else
                    itemArray[a] = new cc.Sprite(gpNamespace.mail.Mail_itemBackground1);

                //名字
                var nickName = new cc.LabelTTF(gpNamespace.TyFriendData[a][7], "Arial", 25);
                nickName.attr({
                    x: 30,
                    y: 10,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(nickName);
                nickName.setTag(1);

                //钩钩
                var gougou = new cc.Sprite(gpNamespace.mail.Mail_gougou);
                gougou.attr({
                    x: 518,
                    y: 5,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(gougou);
                gougou.setVisible(false);
                gougou.setTag(2);

                //按钮
                var modelItem = new cc.MenuItemImage(gpNamespace.mail.Mail_itemBackground2, gpNamespace.mail.Mail_itemBackground2, mailLayer.modelCallbackFunction, mailLayer);
                modelItem.attr({
                    x: 614 / 2,
                    y: 48 / 2
                });
                modelItem.setUserData([a]);
                var modelMenu = new gpNamespace.TyMenu(modelItem);
                modelMenu.attr({
                    x: 0,
                    y: 0
                });
                itemArray[a].addChild(modelMenu);
                modelMenu.setTouchArea(mailLayer.scrollview4.touchArea);
            }

            mailLayer.scrollview4.setMyContainer(itemArray, 48, 1);
        }*/
    },

    headCallbackFunction: function (sender) {
        cc.log("某个好友头部");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonMailSocial, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        var friendLayer = this.friendLayer;

        var index = data[0];

        gpNamespace.TyFriendDeleteData = [];
        gpNamespace.TyFriendDeleteData.push(gpNamespace.TyFriendData[index]);

        var friendID = gpNamespace.TyFriendData[index][2];
        var headImageID = gpNamespace.TyFriendData[index][4];
        var nickName = gpNamespace.TyFriendData[index][7];
        var sex = gpNamespace.TyFriendData[index][5];
        var gold = gpNamespace.TyFriendData[index][3];

        friendLayer.searchField.setVisible(false);
        friendLayer.talkField.setVisible(false);
        var myNodes = [];
        myNodes.push(friendLayer.searchField, friendLayer.talkField);

        var runningScene = cc.director.getRunningScene();
        var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        tyModelLayer1.setMyNodes(myNodes);
        var tyModelLayer = new gpNamespace.TyModelLayer();
        tyModelLayer.setTouchArea(cc.size(564, 354), cc.p(365, 195));
        tyModelLayer1.addChild(tyModelLayer);
        runningScene.addChild(tyModelLayer1, 10);

        var tySearchFriendLayer = new gpNamespace.TySearchFriendLayer(friendID);
        tySearchFriendLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(tySearchFriendLayer);
        tySearchFriendLayer.setMyNodes(myNodes);
        tySearchFriendLayer.setParentNode(friendLayer);

        var img = new LoadHead(headImageID);
        img.loadImg();
        tySearchFriendLayer.setUserHead(img);
        tySearchFriendLayer.setUserNickName(nickName);
        if (sex == "男")
            tySearchFriendLayer.setUserSex(gpNamespace.Sex.Man);
        else
            tySearchFriendLayer.setUserSex(gpNamespace.Sex.Woman);
        tySearchFriendLayer.setUserID(friendID);
        tySearchFriendLayer.setUserGold(gold);

        tySearchFriendLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
    },

    friendOneCallbackFunction: function (sender) {
        cc.log("某个好友");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonMailSocial, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        var friendLayer = this.friendLayer;

        var tag = data[0] + 1;

        var items = friendLayer.scrollview1.array;

        var touchItem = friendLayer.scrollview1.container.getChildByTag(tag);

        for (var a = 0; a < items.length; a++) {
            items[a].getChildByTag(1).setVisible(false);
            if (items[a] == touchItem.getChildren()[0])
                items[a].getChildByTag(1).setVisible(true);
        }

        //var items = friendLayer.scrollview1.scrollview.container.getChildren();
        //
        //var touchItem = friendLayer.scrollview1.scrollview.container.getChildByTag(tag);
        //
        //for (var a = 0; a < items.length; a++) {
        //    if (items[a].getTag() == -1)
        //        continue;
        //    items[a].getChildren()[0].getChildByTag(1).setVisible(false);
        //    if (items[a] == touchItem)
        //        items[a].getChildren()[0].getChildByTag(1).setVisible(true);
        //}
    },

    talkCallbackFunction: function (sender) {
        cc.log("社交聊天");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonMailSocial, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        var friendLayer = this.friendLayer;

        var index = data[0];

        var nickName = data[1];

        var friendID = gpNamespace.TyFriendData[index][2];
        gpNamespace.TalkToID = friendID;

        friendLayer.talkField.setString("@" + nickName + " ");
    },

    onEditFriend: function (event) {
        cc.log("onEditFriend");

        var editFriend = event.getUserData();

        var friendLayer = this.friendLayer;

        //cc.log("result:" + editFriend.result);

        switch (editFriend.result) {
            case 1://申请成功
                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("申请成功，请等待对方添加！");
                runningScene.addChild(tyJumpLayerWithText, 20);

                break;

            case 2://已经申请过
                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("您已申请过，请勿重复申请！");
                runningScene.addChild(tyJumpLayerWithText, 20);

                break;

            case 3://已经是好友
                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("对方已是您的好友，请勿重复申请！");
                runningScene.addChild(tyJumpLayerWithText, 20);

                break;

            case 4://自己好友上限
                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("已达好友上限！");
                runningScene.addChild(tyJumpLayerWithText, 20);

                break;

            case 5://删除成功
                for (var a = 0; a < gpNamespace.TyFriendData.length; a++) {
                    for (var b = 0; b < gpNamespace.TyFriendDeleteData.length; b++) {
                        if (gpNamespace.TyFriendDeleteData[b][2] == gpNamespace.TyFriendData[a][2]) {
                            gpNamespace.TyFriendData.splice(a, 1);

                            friendLayer.scheduleOnce(this.refreshFriendList, 0.2);
                        }
                    }
                }

                break;

            case 6://删除失败
                gpNamespace.TyFriendDeleteData = [];
                friendLayer.scheduleOnce(this.refreshFriendList, 0.2);

                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("删除失败！");
                runningScene.addChild(tyJumpLayerWithText, 20);

                break;

            case 7://自己不能申请自己
                var runningScene = cc.director.getRunningScene();
                var tyJumpLayerWithText = new gpNamespace.TyJumpLayerWithTextRemoved();
                tyJumpLayerWithText.setLabelText("无法申请自己为好友！");
                runningScene.addChild(tyJumpLayerWithText, 20);

                break;
        }
    },

    onFriendVerify: function (event) {
        cc.log("onFriendVerify");

        var friendVerify = event.getUserData();

        var friendLayer = this.friendLayer;

        //cc.log("itemCount:" + friendVerify.itemCount);
        //for (var a = 0; a < friendVerify.itemCount; a++) {
        //    cc.log("userID:" + friendVerify.verifies[a][0]);
        //    cc.log("friendID:" + friendVerify.verifies[a][1]);
        //    cc.log("nickName:" + friendVerify.verifies[a][2]);
        //    cc.log("--------------------------");
        //}

        for (var a = 0; a < friendVerify.itemCount; a++) {
            gpNamespace.TyFriendVerifyData[a] = [];
            gpNamespace.TyFriendVerifyData[a][0] = friendVerify.verifies[a][0];        //userID          用户id
            gpNamespace.TyFriendVerifyData[a][1] = friendVerify.verifies[a][1];        //friendID        用户id 显示用
            gpNamespace.TyFriendVerifyData[a][2] = friendVerify.verifies[a][2];        //nickName        昵称
        }

        if (friendVerify.itemCount == 0) {
            var noFriendVerify = new cc.Sprite(gpNamespace.sj.Sj_noFriendVerify);
            noFriendVerify.attr({
                x: friendLayer.scrollview2.container.getContentSize().width / 2,
                y: friendLayer.scrollview2.container.getContentSize().height - 50
            });
            friendLayer.scrollview2.container.addChild(noFriendVerify);
        }

        var itemArray = [];
        for (var a = 0; a < friendVerify.itemCount; a++) {
            //背景
            itemArray[a] = new cc.Sprite(gpNamespace.sj.Sj_friendVerifyBackground);

            //nickName
            var nickName = new cc.LabelTTF(friendVerify.verifies[a][2], "Arial", 22);
            nickName.setFontFillColor(cc.color(57, 57, 57, 255));
            nickName.attr({
                x: 25,
                y: 50,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(nickName);

            //label
            var label = new cc.LabelTTF("将添加您为好友", "Arial", 22);
            label.setFontFillColor(cc.color(57, 57, 57, 255));
            label.attr({
                x: 25,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(label);

            //取消
            var cancelItem = new cc.MenuItemImage(gpNamespace.sj.Sj_cancel, gpNamespace.sj.Sj_cancel, this.cancelCallbackFunction, this);
            cancelItem.attr({
                x: 55 / 2,
                y: 57 / 2
            });
            cancelItem.setUserData([friendVerify.verifies[a][0], a]);
            var cancelMenu = new gpNamespace.TyMenu(cancelItem);
            cancelMenu.attr({
                x: 210,
                y: 18
            });
            itemArray[a].addChild(cancelMenu);
            cancelMenu.setTouchArea(friendLayer.scrollview2.touchArea);

            //确定
            var confirmItem = new cc.MenuItemImage(gpNamespace.sj.Sj_confirm, gpNamespace.sj.Sj_confirm, this.confirmCallbackFunction, this);
            confirmItem.attr({
                x: 55 / 2,
                y: 57 / 2
            });
            confirmItem.setUserData([friendVerify.verifies[a][0], a]);
            var confirmMenu = new gpNamespace.TyMenu(confirmItem);
            confirmMenu.attr({
                x: 283,
                y: 18
            });
            itemArray[a].addChild(confirmMenu);
            confirmMenu.setTouchArea(friendLayer.scrollview2.touchArea);
        }

        friendLayer.scrollview2.setMyContainer(itemArray, 100, 1);
    },

    confirmCallbackFunction: function (sender) {
        cc.log("确定添加好友");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonMailSocial, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();
        var responseType = 1;
        var userID = data[0].toString().split(",");
        var tag = data[1] + 1;

        //cc.log("userID:" + userID);

        xinyou.netManager.addFriendResponse(responseType, userID);

        var friendLayer = this.friendLayer;
        var item = friendLayer.scrollview2.container.getChildByTag(tag);

        var action = cc.moveBy(0.5, 360, 0);
        item.runAction(action.easing(cc.easeBackIn()));
    },

    cancelCallbackFunction: function (sender) {
        cc.log("取消添加好友");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonMailSocial, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();
        var responseType = 2;
        var userID = data[0].toString().split(",");
        var tag = data[1] + 1;

        //cc.log("userID:" + userID);

        xinyou.netManager.addFriendResponse(responseType, userID);

        var friendLayer = this.friendLayer;
        var item = friendLayer.scrollview2.scrollview.container.getChildByTag(tag);

        var action = cc.moveBy(0.5, -360, 0);
        item.runAction(action.easing(cc.easeBackIn()));
    },

    onFriendResponse: function (event) {
        cc.log("onFriendResponse");

        var friendResponse = event.getUserData();

        var friendLayer = this.friendLayer;

        //cc.log("responseType:" + friendResponse.responseType);
        //cc.log("itemCount:" + friendResponse.itemCount);
        //for (var a = 0; a < friendResponse.itemCount; a++) {
        //    cc.log("diamond:" + friendResponse.friends[a][0]);
        //    cc.log("voucher:" + friendResponse.friends[a][1]);
        //    cc.log("friendID:" + friendResponse.friends[a][2]);
        //    cc.log("gold:" + friendResponse.friends[a][3]);
        //    cc.log("headImageID:" + friendResponse.friends[a][4]);
        //    cc.log("gender:" + friendResponse.friends[a][5]);
        //    cc.log("headImagePath:" + friendResponse.friends[a][6]);
        //    cc.log("nickName:" + friendResponse.friends[a][7]);
        //    cc.log("--------------------------");
        //}

        switch (friendResponse.responseType) {
            case 1:
            case 3:
                if (friendResponse.itemCount == 0) {
                    friendLayer.scheduleOnce(this.refreshFriendVerifyList, 0.2);
                } else {
                    //本地好友列表添加新记录
                    var newFriend = [];
                    for (var a = 0; a < friendResponse.itemCount; a++) {
                        newFriend[a] = [];
                        newFriend[a][0] = friendResponse.friends[a][0];
                        newFriend[a][1] = friendResponse.friends[a][1];
                        newFriend[a][2] = friendResponse.friends[a][2];
                        newFriend[a][3] = friendResponse.friends[a][3];
                        newFriend[a][4] = friendResponse.friends[a][4];
                        newFriend[a][5] = friendResponse.friends[a][5];
                        newFriend[a][6] = friendResponse.friends[a][6];
                        newFriend[a][7] = friendResponse.friends[a][7];
                    }

                    var newFriends = newFriend.concat(gpNamespace.TyFriendData);
                    gpNamespace.TyFriendData = newFriends;

                    //for (var a = 0; a < gpNamespace.TyFriendData.length; a++) {
                    //    cc.log("diamond:" + gpNamespace.TyFriendData[a][0]);
                    //    cc.log("voucher:" + gpNamespace.TyFriendData[a][1]);
                    //    cc.log("friendID:" + gpNamespace.TyFriendData[a][2]);
                    //    cc.log("gold:" + gpNamespace.TyFriendData[a][3]);
                    //    cc.log("headImageID:" + gpNamespace.TyFriendData[a][4]);
                    //    cc.log("gender:" + gpNamespace.TyFriendData[a][5]);
                    //    cc.log("headImagePath:" + gpNamespace.TyFriendData[a][6]);
                    //    cc.log("nickName:" + gpNamespace.TyFriendData[a][7]);
                    //}

                    friendLayer.scheduleOnce(this.refreshFriendList, 0.2);

                    for (var a = 0; a < friendResponse.itemCount; a++) {
                        for (var b = 0; b < gpNamespace.TyFriendVerifyData.length; b++) {
                            if (friendResponse.friends[a][2] == gpNamespace.TyFriendVerifyData[b][1]) {
                                gpNamespace.TyFriendVerifyData.splice(b, 1);
                            }
                        }
                    }

                    //for (var a = 0; a < gpNamespace.TyFriendVerifyData.length; a++) {
                    //    cc.log("userID:" + gpNamespace.TyFriendVerifyData[a][0]);
                    //    cc.log("friendID:" + gpNamespace.TyFriendVerifyData[a][1]);
                    //    cc.log("nickName:" + gpNamespace.TyFriendVerifyData[a][2]);
                    //}

                    friendLayer.scheduleOnce(this.refreshFriendVerifyList, 0.2);
                }

                break;

            case 2:
                if (friendResponse.itemCount == 0) {
                    friendLayer.scheduleOnce(this.refreshFriendVerifyList, 0.2);
                } else {
                    for (var a = 0; a < friendResponse.itemCount; a++) {
                        for (var b = 0; b < gpNamespace.TyFriendVerifyData.length; b++) {
                            if (friendResponse.friends[a][2] == gpNamespace.TyFriendVerifyData[b][1]) {
                                gpNamespace.TyFriendVerifyData.splice(b, 1);
                            }
                        }
                    }
                    friendLayer.scheduleOnce(this.refreshFriendVerifyList, 0.2);
                }

                break;

            case 4:
                if (friendResponse.itemCount == 0) {
                    friendLayer.scheduleOnce(this.refreshFriendVerifyList, 0.2);
                } else {
                    gpNamespace.TyFriendVerifyData = [];
                    friendLayer.scheduleOnce(this.refreshFriendVerifyList, 0.2);
                }

                break;
        }
    },

    refreshFriendList: function () {
        var friendLayer = this;

        friendLayer.scrollview1.clearContainer();

        if (gpNamespace.TyFriendData.length == 0) {
            var noFriend = new cc.Sprite(gpNamespace.sj.Sj_noFriend);
            noFriend.attr({
                x: friendLayer.scrollview1.container.getContentSize().width / 2,
                y: friendLayer.scrollview1.container.getContentSize().height - 50
            });
            friendLayer.scrollview1.container.addChild(noFriend);

            return;
        }

        var itemArray = [];
        for (var a = 0; a < gpNamespace.TyFriendData.length; a++) {
            //背景
            if (a % 2)
                itemArray[a] = new cc.Sprite(gpNamespace.sj.Sj_friendBackground1);
            else
                itemArray[a] = new cc.Sprite(gpNamespace.sj.Sj_friendBackground2);

            //选中黄色
            var yellow = new cc.Sprite(gpNamespace.sj.Sj_yellow);
            yellow.attr({
                x: 0,
                y: 0,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(yellow);
            yellow.setTag(1);
            yellow.setVisible(false);

            //好友头像背景
            var friendHeadBackground = new cc.Sprite(gpNamespace.sj.Sj_friendHeadBackground1);
            if (gpNamespace.TyFriendData[a][5] == "女") {
                friendHeadBackground = new cc.Sprite(gpNamespace.sj.Sj_friendHeadBackground2);
            }
            friendHeadBackground.attr({
                x: 10,
                y: 1,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(friendHeadBackground);

            //头像
            var headID = gpNamespace.TyFriendData[a][4];
            var img = new LoadHead(headID);
            img.loadImg();
            img.setScaleX(0.6);
            img.setScaleY(0.5);
            img.setPosition(friendHeadBackground.getContentSize().width / 2, friendHeadBackground.getContentSize().height / 2);
            friendHeadBackground.addChild(img);

            //好友头像边框
            var friendHeadBorder = new cc.Sprite(gpNamespace.sj.Sj_friendHeadBorder);
            friendHeadBorder.attr({
                x: 0,
                y: 0,
                anchorX: 0,
                anchorY: 0
            });
            friendHeadBackground.addChild(friendHeadBorder);

            //昵称label
            var nickNameLabel = new cc.LabelTTF("昵称：", "Arial", 21);
            nickNameLabel.setFontFillColor(cc.color(108, 28, 11, 255));
            nickNameLabel.attr({
                x: 96,
                y: 56,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(nickNameLabel);

            //昵称
            var nickName = new cc.LabelTTF(gpNamespace.TyFriendData[a][7], "Arial", 21);
            nickName.setFontFillColor(cc.color(108, 28, 11, 255));
            nickName.attr({
                x: 156,
                y: 56,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(nickName);

            //ID label
            var IDLabel = new cc.LabelTTF("ID：", "Arial", 21);
            IDLabel.setFontFillColor(cc.color(108, 28, 11, 255));
            IDLabel.attr({
                x: 96,
                y: 22,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(IDLabel);

            //ID
            var ID = new cc.LabelTTF(gpNamespace.TyFriendData[a][2].toString(), "Arial", 21);
            ID.setFontFillColor(cc.color(108, 28, 11, 255));
            ID.attr({
                x: 130,
                y: 22,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(ID);

            var tyNet = gpNamespace.TyNetManager.getInstance();

            //好友条
            var friendItem = new cc.MenuItemImage(gpNamespace.sj.Sj_model, gpNamespace.sj.Sj_model, tyNet.friendOneCallbackFunction, tyNet);
            friendItem.attr({
                x: 260 / 2,
                y: 90 / 2
            });
            friendItem.setUserData([a]);
            var friendMenu = new gpNamespace.TyMenu(friendItem);
            friendMenu.attr({
                x: 0,
                y: 0
            });
            itemArray[a].addChild(friendMenu);
            friendMenu.setTouchArea(friendLayer.scrollview1.touchArea);

            //头部点击按钮
            var headItem = new cc.MenuItemImage(gpNamespace.sj.Sj_modelHead, gpNamespace.sj.Sj_modelHead, tyNet.headCallbackFunction, tyNet);
            headItem.attr({
                x: 85 / 2,
                y: 90 / 2
            });
            headItem.setUserData([a]);
            var headMenu = new gpNamespace.TyMenu(headItem);
            headMenu.attr({
                x: 0,
                y: 0
            });
            itemArray[a].addChild(headMenu);
            headMenu.setTouchArea(friendLayer.scrollview1.touchArea);

            //聊天
            var talkItem = new cc.MenuItemImage(gpNamespace.sj.Sj_talk, gpNamespace.sj.Sj_talk, tyNet.talkCallbackFunction, tyNet);
            talkItem.attr({
                x: 66 / 2,
                y: 53 / 2
            });
            talkItem.setUserData([a, gpNamespace.TyFriendData[a][7]]);
            var talkMenu = new gpNamespace.TyMenu(talkItem);
            talkMenu.attr({
                x: 265,
                y: 19
            });
            itemArray[a].addChild(talkMenu);
            talkMenu.setTouchArea(friendLayer.scrollview1.touchArea);
        }

        friendLayer.scrollview1.setMyContainer(itemArray, 100, 1);
    },

    refreshFriendVerifyList: function () {
        var friendLayer = this;

        friendLayer.scrollview2.clearContainer();

        xinyou.netManager.getGameNotice();

        if (gpNamespace.TyFriendVerifyData.length == 0) {
            var noFriendVerify = new cc.Sprite(gpNamespace.sj.Sj_noFriendVerify);
            noFriendVerify.attr({
                x: friendLayer.scrollview2.container.getContentSize().width / 2,
                y: friendLayer.scrollview2.container.getContentSize().height - 50
            });
            friendLayer.scrollview2.container.addChild(noFriendVerify);

            return;
        }

        var itemArray = [];
        for (var a = 0; a < gpNamespace.TyFriendVerifyData.length; a++) {
            //背景
            itemArray[a] = new cc.Sprite(gpNamespace.sj.Sj_friendVerifyBackground);

            //nickName
            var nickName = new cc.LabelTTF(gpNamespace.TyFriendVerifyData[a][2], "Arial", 22);
            nickName.setFontFillColor(cc.color(57, 57, 57, 255));
            nickName.attr({
                x: 25,
                y: 50,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(nickName);

            //label
            var label = new cc.LabelTTF("将添加您为好友", "Arial", 22);
            label.setFontFillColor(cc.color(57, 57, 57, 255));
            label.attr({
                x: 25,
                y: 20,
                anchorX: 0,
                anchorY: 0
            });
            itemArray[a].addChild(label);

            var tyNet = gpNamespace.TyNetManager.getInstance();

            //确定
            var confirmItem = new cc.MenuItemImage(gpNamespace.sj.Sj_confirm, gpNamespace.sj.Sj_confirm, tyNet.confirmCallbackFunction, tyNet);
            confirmItem.attr({
                x: 55 / 2,
                y: 57 / 2
            });
            confirmItem.setUserData([gpNamespace.TyFriendVerifyData[a][0], a]);
            var confirmMenu = new gpNamespace.TyMenu(confirmItem);
            confirmMenu.attr({
                x: 283,
                y: 18
            });
            itemArray[a].addChild(confirmMenu);
            confirmMenu.setTouchArea(friendLayer.scrollview2.touchArea);

            //取消
            var cancelItem = new cc.MenuItemImage(gpNamespace.sj.Sj_cancel, gpNamespace.sj.Sj_cancel, tyNet.cancelCallbackFunction, tyNet);
            cancelItem.attr({
                x: 55 / 2,
                y: 57 / 2
            });
            cancelItem.setUserData([gpNamespace.TyFriendVerifyData[a][0], a]);
            var cancelMenu = new gpNamespace.TyMenu(cancelItem);
            cancelMenu.attr({
                x: 210,
                y: 18
            });
            itemArray[a].addChild(cancelMenu);
            cancelMenu.setTouchArea(friendLayer.scrollview2.touchArea)
        }
        friendLayer.scrollview2.setMyContainer(itemArray, 100, 1);
    },

    onSearchFriend: function (event) {
        cc.log("onSearchFriend");

        var searchFriend = event.getUserData();

        var friendLayer = this.friendLayer;

        var typeID = friendLayer.searchField.getString();

        //cc.log("canSearch:" + searchFriend.canSearch);
        //cc.log("diamond:" + searchFriend.diamond);
        //cc.log("voucher:" + searchFriend.voucher);
        //cc.log("friendID:" + searchFriend.friendID);
        //cc.log("gold:" + searchFriend.gold);
        //cc.log("headImageID:" + searchFriend.headImageID);
        //cc.log("gender:" + searchFriend.gender);
        //cc.log("headImagePath:" + searchFriend.headImagePath);
        //cc.log("nickName:" + searchFriend.nickName);

        if (searchFriend.friendID == 0) {
            friendLayer.searchField.setVisible(false);
            friendLayer.talkField.setVisible(false);
            var myNodes = [];
            myNodes.push(friendLayer.searchField, friendLayer.talkField);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            tyModelLayer1.setMyNodes(myNodes);
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(576, 185), cc.p(351, 317));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var tySearchNOLayer = new gpNamespace.TySearchNOLayer(typeID);
            tySearchNOLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tySearchNOLayer);

            var visible = new cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height));
            tySearchNOLayer.runAction(visible.easing(cc.easeBackOut()));
        }
        else {
            friendLayer.searchField.setVisible(false);
            friendLayer.talkField.setVisible(false);
            var myNodes = [];
            myNodes.push(friendLayer.searchField, friendLayer.talkField);

            var runningScene = cc.director.getRunningScene();
            var tyModelLayer1 = new gpNamespace.TyModelLayer1();
            tyModelLayer1.setMyNodes(myNodes);
            var tyModelLayer = new gpNamespace.TyModelLayer();
            tyModelLayer.setTouchArea(cc.size(564, 354), cc.p(365, 195));
            tyModelLayer1.addChild(tyModelLayer);
            runningScene.addChild(tyModelLayer1, 10);

            var tySearchYESLayer = new gpNamespace.TySearchYESLayer(searchFriend.friendID);
            tySearchYESLayer.attr({
                x: 0,
                y: cc.winSize.height
            });
            tyModelLayer.addChild(tySearchYESLayer);
            tySearchYESLayer.setMyNodes(myNodes);

            var img = new LoadHead(searchFriend.headImageID);
            img.loadImg();
            tySearchYESLayer.setUserHead(img);
            tySearchYESLayer.setUserNickName(searchFriend.nickName);
            if (searchFriend.gender == "男")
                tySearchYESLayer.setUserSex(gpNamespace.Sex.Man);
            else
                tySearchYESLayer.setUserSex(gpNamespace.Sex.Woman);
            tySearchYESLayer.setUserID(searchFriend.friendID);
            tySearchYESLayer.setUserGold(searchFriend.gold);

            tySearchYESLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
        }
    },

    onGetTalk: function (event) {
        cc.log("onGetTalk");
        xinyou.netManager.getHistoryTalk();
        var talk = event.getUserData();

        var friendLayer = this.friendLayer;

        //cc.log("chatType:" + talk.chatType);
        //cc.log("userID:" + talk.userID);
        //cc.log("toUserID:" + talk.toUserID);
        //cc.log("content:" + talk.content);
        //cc.log("toNickName:" + talk.toNickName);
        //cc.log("nickName:" + talk.nickName);

        var singleLength = 40;
        var singleHeight = 30;

        gpNamespace.TyTalkData = [];
        var firstStr = "[" + talk.nickName + "]:";
        if (talk.chatType == 1 && talk.nickName == userInfo.nickName)
            firstStr = "[@" + talk.toNickName + "]:";
        var secondStr = talk.content;
        var str = firstStr + secondStr;
        cc.log(">>>>>>>>>>>>>>>>>>>>"+str);
      
//        var strArray = gpNamespace.GetSlicedArray(str, singleLength);
        var strArray = str.substring(0, 40)+"..";
        for (var a = 0; a < strArray.length; a++) {
            var str = "";
            var isSelf = 0;
            var nickName = userInfo.nickName;
            if (talk.nickName == nickName)
                isSelf = 1;
            if (firstStr == strArray[a].substr(0, firstStr.length)) {
                str = strArray[a] + "|" + firstStr + "|" + talk.nickName + "|" + talk.userID + "|" + talk.chatType + "|" + isSelf;
                gpNamespace.TySocialData.push(str);
            }
            else {
                str = strArray[a] + "|" + "" + "|" + "" + "|" + 0 + "|" + talk.chatType + "|" + isSelf;
                gpNamespace.TySocialData.push(str);
            }
        }

        if (!friendLayer)
            return;


        friendLayer.scrollview3.clearContainer();

        for (var a = 0; a < gpNamespace.TySocialData.length; a++) {
            friendLayer.scrollview3.addLine(singleHeight);
            var tag = friendLayer.scrollview3.rowIndex;
            var item = friendLayer.scrollview3.container.getChildByTag(tag);

            var strArray = gpNamespace.TySocialData[a].split("|");
            cc.log("TySocialData>>>>>>>>>>"+strArray);
            var label = new cc.LabelTTF(strArray[0], "Arial", 25);
            switch (strArray[4]) {
                case "1": // 私聊
                    label.setFontFillColor(cc.color(210, 97, 195, 255));
                    break;
                case "2": // 公聊
                    if (strArray[5] == 0)
                        label.setFontFillColor(cc.color(6, 255, 0, 255));
                    break;
                case "3": // 系统
                    label.setFontFillColor(cc.color(241, 211, 43, 255));
                    break;
            }
            label.attr({
                x: 0,
                y: 0,
                anchorX: 0,
                anchorY: 0
            });
            item.addChild(label);

            if (strArray[1] != "") {
                var menuItem = new cc.MenuItemFont(strArray[1], this.callBackFunction, friendLayer);
                menuItem.attr({
                    x: menuItem.getContentSize().width / 2,
                    y: menuItem.getContentSize().height / 2 - 3
                });
                menuItem.setUserData([strArray[2], strArray[3], this.self]);
                menuItem.setScale(0.8);
                var menu = new gpNamespace.TyMenu(menuItem);
                menu.attr({
                    x: 0,
                    y: 0
                });
                item.addChild(menu);
                menu.setTouchArea(friendLayer.scrollview3.touchArea);
                menu.setTouchListener();

                label.setString(strArray[0].substring(strArray[1].length, strArray[0].length));
                label.setPositionX(menuItem.getContentSize().width);
            }
        }
    },
    //聊天室
    onGetHistoryTalk: function (event) {
        cc.log("onGetHistoryTalk");
        var historyTalk = event.getUserData();
        historyTalkInfo = historyTalk;
        cc.log(historyTalk.itemCount);
        gpNamespace.pdkcharType = [];
        gpNamespace.TySocialTemp = [];
        if (historyTalk.itemCount != 0) {
            var singleLength = 40;
            var singleHeight = 30;
            cc.log("historyTalk.itemCount"+historyTalk.itemCount);
            
            this.setFirstBar(historyTalk.talks[0][3],historyTalk.talks[0][2]);
            
            for(var a=1; a<historyTalk.itemCount; a++){
            	var firstStr = historyTalk.talks[a][3] + ": ";
            	var secondStr = historyTalk.talks[a][2];
            	var str = firstStr+secondStr;
            	var realLength = tyNamespace.GetRealLength(str);
            	tyNamespace.SlicedString = [];
            	tyNamespace.GetSlicedString(str,60);
            	str = tyNamespace.SlicedString[0];
            	if(realLength>60){
            		str = str+"...";
            	}
            	var realLengthnew = tyNamespace.GetRealLength(str);
            	//chatType为3时为系统信息
            	//用户的nickName判断是
            	//1 自己2 公聊  3系统 pdkcharType
            	cc.log("strlength:>>>>>>>>>>>>>>>>>>>>"+str.length);
            	cc.log("Type:>>>>>>>>>>>>>>>>>>>"+historyTalk.talks[a][0]);
            	cc.log("user:>>>>>>>>>>>>>>>>>>>"+historyTalk.talks[a][1]);
            	cc.log("my>>>>>>>>>>>>>>>>>>>>"+gpNamespace.LoginInfo.USERID);
            	pdkcharType = 2;
            	var myArray = new Array();
            	if(this.readArrayToLong(historyTalk.talks[a][1])==this.readArrayToLong(gpNamespace.LoginInfo.USERID)){
            		cc.log("自己发的消息");
            		if(realLengthnew > 40){
            			gpNamespace.pdkcharType.push(1);
            			cc.log("大于20字符>>>>>>>>>>>>>>>>>>>>");
            		}
            		gpNamespace.pdkcharType.push(1);
            	}else if(historyTalk.talks[a][0]==2){
            		cc.log("公聊的消息");
            		if(realLengthnew > 40){
            			gpNamespace.pdkcharType.push(2);
            		}
            		gpNamespace.pdkcharType.push(2);
            	}else if(historyTalk.talks[a][0]==3){
            		cc.log("系统的消息");
            		if(realLengthnew > 40){
            			gpNamespace.pdkcharType.push(3);
            		}
            		gpNamespace.pdkcharType.push(3);
            	}
            	gpNamespace.TySocialTemp.push(str);
            }
            
            cc.log("gpNamespace.pdkcharType.length>>>>>>>>>>>>>>>>>>>>"+gpNamespace.pdkcharType.length);
            cc.log("gpNamespace.TySocialTemp.length>>>>>>>>>>>>>>>>>>>"+gpNamespace.TySocialTemp.length);
            this.gpMiddleLayer&&this.gpMiddleLayer.setFriendsContainer(gpNamespace.TySocialTemp);
        }
    },
    
    setFirstBar:function(name,content){
    	firstStr = "系统消息:"+content;
    	cc.log(">>>>>>>>>>>>>>>>>>>>>>>>>>"+firstStr+firstStr.length);
    	var realLength = tyNamespace.GetRealLength(firstStr);
    	tyNamespace.SlicedString = [];
    	tyNamespace.GetSlicedString(firstStr,60);
    	firstStr = tyNamespace.SlicedString[0];
    	if(realLength>60){
    		firstStr = firstStr+"...";
    	}
    	if(realLength>40){
    		gpNamespace.systemMessageLength=2;
    	}else if(realLength <= 40){
    		gpNamespace.systemMessageLength = 1;
    	}
    	this.gpMiddleLayer&&this.gpMiddleLayer.setFirstLineContainer(firstStr);
    },
    
    readArrayToLong: function (array) {
    	return (
    			((array[0]) * 0x100000000000000) +
    			((array[1]) * 0x1000000000000) +
    			((array[2]) * 0x10000000000) +
    			((array[3]) * 0x100000000) +
    			((array[4]) * 0x1000000) +
    			((array[5]) * 0x10000) +
    			((array[6]) * 0x100) +
    			((array[7]) * 0x1)
    	);
    },
 
    onGetHistoryLaba: function (event) {
        cc.log("onGetHistoryLaba");

        var historyTalk = event.getUserData();
        gpNamespace.HistoryLabaInfo.ITEMCOUNT = historyTalk.itemCount;
        gpNamespace.HistoryLabaInfo.TALKS = historyTalk.talks;
        lastThreeNews = [historyTalk.talks[historyTalk.itemCount-1],historyTalk.talks[historyTalk.itemCount-2],historyTalk.talks[historyTalk.itemCount-3]];
        cc.log("lastThreeNews[0][2]:"+lastThreeNews[0][2]);
        cc.log("lastThreeNews[0][2]:"+lastThreeNews[1][2]);
        cc.log("lastThreeNews[0][2]:"+lastThreeNews[2][2]);
        if (historyTalk.itemCount == 0)
            return;
        else{
        	/*for(var i = 0; i<historyTalk.itemCount; i++){
        		cc.log("historyTalk:"+historyTalk.talks[i][0]);
        		cc.log("historyTalk:"+historyTalk.talks[i][1]);
        		cc.log("historyTalk:"+historyTalk.talks[i][2]);
        		cc.log("historyTalk:"+historyTalk.talks[i][3]);
        	}*/
        	this.sjpdLayer && this.sjpdLayer.setNewsList(historyTalk);
        }
        //cc.log("itemCount:" + historyTalk.itemCount);
        //for (var a = 0; a < historyTalk.itemCount; a++) {
        //    cc.log("chatType:" + historyTalk.talks[a][0]);
        //    cc.log("userID:" + historyTalk.talks[a][1]);
        //    cc.log("content:" + historyTalk.talks[a][2]);
        //    cc.log("nickName:" + historyTalk.talks[a][3]);
        //}

        /*gpNamespace.TyGonggaoTemp = [];
        gpNamespace.TyLabaTemp = [];

        var singleLength = 66;
        var singleHeight = 30;

        for (var a = 0; a < historyTalk.itemCount; a++) {
            gpNamespace.TyGonggaoTemp.push(historyTalk.talks[a][3] + ":" + historyTalk.talks[a][2] + "|" + historyTalk.talks[a][0]);
            if (gpNamespace.TyGonggaoTemp.length > 3)
                gpNamespace.TyGonggaoTemp.shift();

            gpNamespace.TyTalkData = [];
            var firstStr = "[" + historyTalk.talks[a][3] + "]:";
            var secondStr = historyTalk.talks[a][2];
            var str = firstStr + secondStr;
            var strArray = gpNamespace.GetSlicedArray(str, singleLength);

            for (var b = 0; b < strArray.length; b++) {
                var str = "";
                var isSelf = 0;
                var nickName = userInfo.nickName;
                if (historyTalk.talks[a][3] == nickName)
                    isSelf = 1;
                if (firstStr == strArray[b].substr(0, firstStr.length)) {
                    str = strArray[b] + "|" + firstStr + "|" + historyTalk.talks[a][3] + "|" + historyTalk.talks[a][1] + "|" + historyTalk.talks[a][0] + "|" + isSelf;
                    gpNamespace.TyLabaTemp.push(str);
                }
                else {
                    str = strArray[b] + "|" + "" + "|" + "" + "|" + 0 + "|" + historyTalk.talks[a][0] + "|" + isSelf;
                    gpNamespace.TyLabaTemp.push(str);
                }
                if (gpNamespace.TyLabaTemp.length > 20) {
                    gpNamespace.TyLabaTemp.shift();
                }
            }
        }

        gpNamespace.TyGonggaoData = gpNamespace.TyGonggaoTemp;
        gpNamespace.TyLabaData = gpNamespace.TyLabaTemp;*/
    },

    callBackFunction: function (sender) {
        cc.log("聊天名字");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonMailSocial, false);

        tyNamespace.setMenuEnable(sender);

        sender.setScaleY(0.8);

        var data = sender.getUserData();

        var name = data[0];

        var id = data[1];

        gpNamespace.TalkToID = id;
        gpNamespace.TalkToName = name;

        var self = data[2];

        var friendLayer = self.friendLayer;

        friendLayer.talkField.setString("@" + name + " ");
    },

    //call1BackFunction: function (sender) {
    //    cc.log("聊天名字");
    //
    //    gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonMailSocial, false);
    //
    //    sender.setScaleY(0.8);
    //
    //    var data = sender.getUserData();
    //
    //    var name = data[0];
    //
    //    var id = data[1];
    //
    //    gpNamespace.TalkToID = id;
    //    gpNamespace.TalkToName = name;
    //
    //    var self = data[2];
    //
    //    var labaLayer = self.labaLayer;
    //
    //    labaLayer.labaField.setString("@" + name + " ");
    //},
//免费砸金蛋
    onEgg: function (event) {
        cc.log("onEgg");

        var egg = event.getUserData();

        var eggLayer = this.eggLayer;
        var bottomLayer = this.bottomLayer;

        if(egg.result == 0){
        	cc.log("diamond:" + egg.diamond);
        	cc.log("cansaiquan:" + egg.cansaiquan);
        	cc.log("voucher:" + egg.voucher);
        	cc.log("gold:" + egg.gold);
        	cc.log("id:" + egg.id);
        	cc.log("itemCount:" + egg.itemCount);
        	cc.log("result:" + egg.result);
//        	cc.log("reward[i][0]奖励种数:"+egg.reward.length);
//	      	cc.log("reward[i][0]奖励类型:"+egg.reward[0][0]);
//	      	cc.log("reward[i][1]数量:"+egg.reward[0][1]);
        	var type = null;
        	for(var i = 0;i<egg.reward.length;i++){
        		type = egg.reward[i][0];
        		cc.log("type:"+type);
        		eggLayer.showRewards(egg.reward[i][0],egg.reward[i][1]);
        		switch (type) {
				case 1:
					cc.log("获得金币："+egg.reward[i][1]);
					break;
				case 2:
					cc.log("获得钻石："+egg.reward[i][1]);
					break;
				case 3:
					cc.log("获得兑换券："+egg.reward[i][1]);
					break;
				case 35:
					cc.log("!!!!!!!!!!!获得周卡："+egg.reward[i][1]);
					break;
				case 36:
					cc.log("!!!!!!!!!!!获得月卡："+egg.reward[i][1]);
					break;

				default:
					break;
				}
        	}

//        	this.topLayer.removeChildByTag(101);
//        	this.topLayer.removeChildByTag(102);
//        	this.topLayer.removeChildByTag(103);
        	this.topLayer.setUserGold(egg.gold);
        	this.topLayer.setUserDiamond(egg.diamond);
        	this.topLayer.setUserVoucher(egg.voucher);
        	
        	this.bottomLayer.setEggTips();
        }

        //1 - 没注册用户不能砸金蛋
        //2 - 你今天已经砸过金蛋了
        //3 - 砸金蛋任务已过期
        //0 成功

        /*if (egg.result == 0) {
            this.topLayer && this.topLayer.setUserGold(egg.gold);
            this.topLayer && this.topLayer.setUserDiamond(egg.diamond);
            this.topLayer && this.topLayer.setUserDui(egg.voucher);

            userInfo.gold = egg.gold;
            userInfo.diamond = egg.diamond;
            userInfo.voucher = egg.voucher;
            userInfo.isKickEgg = true;

            switch (egg.id) {
                case 1://金币
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggSmall, false);
                    }, 2);

                    switch (egg.itemCount) {
                        case 20000:
                            this.eggName = "#zjm_jdd_018u.png";
                            this.eggPic = "#zjm_jdd_022u.png";
                            this.eggInfo = "";
                            break;
                        case 50000:
                            this.eggName = "#zjm_jdd_017u.png";
                            this.eggPic = "#zjm_jdd_023u.png";
                            this.eggInfo = "";
                            break;
                        case 100000:
                            this.eggName = "#zjm_jdd_016u.png";
                            this.eggPic = "#zjm_jdd_024u.png";
                            this.eggInfo = "";
                            break;
                    }
                    break;

                case 2://钻石
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggSmall, false);
                    }, 2);

                    switch (egg.itemCount) {
                        case 5:
                            this.eggName = "#zjm_jdd_005u.png";
                            this.eggPic = "#zjm_jdd_019u.png";
                            this.eggInfo = "";
                            break;
                        case 7:
                            this.eggName = "#zjm_jdd_033u.png";
                            this.eggPic = "#zjm_jdd_019u.png";
                            this.eggInfo = "";
                            break;
                        case 10:
                            this.eggName = "#zjm_jdd_003u.png";
                            this.eggPic = "#zjm_jdd_001u.png";
                            this.eggInfo = "";
                            break;
                    }
                    break;

                case 3://兑换券
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggSmall, false);
                    }, 2);

                    switch (egg.itemCount) {
                        case 100:
                            this.eggName = "#zjm_jdd_013u.png";
                            this.eggPic = "#zjm_jdd_020u.png";
                            this.eggInfo = "";
                            break;
                        case 200:
                            this.eggName = "#zjm_jdd_032u.png";
                            this.eggPic = "#zjm_jdd_020u.png";
                            this.eggInfo = "";
                            break;
                        case 300:
                            this.eggName = "#zjm_jdd_031u.png";
                            this.eggPic = "#zjm_jdd_020u.png";
                            this.eggInfo = "";
                            break;
                        case 400:
                            this.eggName = "#zjm_jdd_030u.png";
                            this.eggPic = "#zjm_jdd_020u.png";
                            this.eggInfo = "";
                            break;
                        case 500:
                            this.eggName = "#zjm_jdd_012u.png";
                            this.eggPic = "#zjm_jdd_020u.png";
                            this.eggInfo = "";
                            break;
                        case 1000:
                            this.eggName = "#zjm_jdd_029u.png";
                            this.eggPic = "#zjm_jdd_021u.png";
                            this.eggInfo = "";
                            break;
                    }
                    break;

                case 35://周卡  道具
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggSmall, false);
                    }, 2);

                    this.eggName = "#zjm_jdd_014u.png";
                    this.eggPic = "#zjm_jdd_025u.png";
                    this.eggInfo = "#zjm_jdd_028u.png";
                    break;

                case 36://月卡  道具
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggSmall, false);
                    }, 2);

                    this.eggName = "#zjm_jdd_015u.png";
                    this.eggPic = "#zjm_jdd_026u.png";
                    this.eggInfo = "#zjm_jdd_028u.png";
                    break;

                case 75://手机  邮箱
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggBig, false);
                    }, 2);

                    this.eggName = "#zjm_jdd_006u.png";
                    this.eggPic = "#zjm_jdd_007u.png";
                    this.eggInfo = "#zjm_jdd_027u.png";
                    break;

                case 113://100充值卡  邮箱
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggBig, false);
                    }, 2);

                    this.eggName = "#zjm_jdd_008u.png";
                    this.eggPic = "#zjm_jdd_009u.png";
                    this.eggInfo = "#zjm_jdd_027u.png";
                    break;

                case 114://50充值卡  邮箱
                    this.eggLayer.scheduleOnce(function () {
                        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEggBig, false);
                    }, 2);

                    this.eggName = "#zjm_jdd_010u.png";
                    this.eggPic = "#zjm_jdd_011u.png";
                    this.eggInfo = "#zjm_jdd_027u.png";
                    break;
            }

            var armature = new ccs.Armature("goldd_002u");
            armature.getAnimation().playWithIndex(0);
            armature.getAnimation().setSpeedScale(1);
            armature.setScale(1);
            armature.setAnchorPoint(0.5, 0.5);
            armature.setPosition(640, 360);
            eggLayer.addChild(armature);
            armature.getAnimation().setMovementEventCallFunc(this.eggCallBackRemove, this);
        }

        if (egg.result == 1) {
            var runningScene = cc.director.getRunningScene();
            var juhua = runningScene.getChildByName(gpNamespace.Juhua);
            juhua && juhua.removeFromParent(true);

            this.eggLayer.getParent().getParent().removeFromParent(true);
            this.qpsLayer.blackEgg.setVisible(true);
            this.qpsLayer.jindanDlbMenu.setVisible(false);

            xinyou.netManager.getRestTime(1);

            gpNamespace.showDialog("您还没有注册，请先完成注册！");
        }

        if (egg.result == 2) {
            var runningScene = cc.director.getRunningScene();
            var juhua = runningScene.getChildByName(gpNamespace.Juhua);
            juhua && juhua.removeFromParent(true);

            this.eggLayer.getParent().getParent().removeFromParent(true);
            this.qpsLayer.blackEgg.setVisible(true);
            this.qpsLayer.jindanDlbMenu.setVisible(false);

            xinyou.netManager.getRestTime(1);

            gpNamespace.showDialog("您今天已经砸过金蛋了！");
        }

        if (egg.result == 3) {
            var runningScene = cc.director.getRunningScene();
            var juhua = runningScene.getChildByName(gpNamespace.Juhua);
            juhua && juhua.removeFromParent(true);

            this.eggLayer.getParent().getParent().removeFromParent(true);
            this.qpsLayer.blackEgg.setVisible(true);
            this.qpsLayer.jindanDlbMenu.setVisible(false);

            xinyou.netManager.getRestTime(1);

            gpNamespace.showDialog("砸金蛋活动已经结束了，请期待下次！");
        }*/
    },

    onGoldEgg: function (event) {
    	cc.log("onGoldEgg开始");

    	var goldEgg = event.getUserData();
    	var eggLayer = this.eggLayer;

//    	cc.log("diamond:" + goldEgg.diamond);
//    	cc.log("cansaiquan:" + goldEgg.cansaiquan);
//    	cc.log("voucher:" + goldEgg.voucher);
//    	cc.log("gold:" + goldEgg.gold);
//    	cc.log("result:" + goldEgg.result);
    	cc.log("itemCount:" + goldEgg.itemCount);
    	cc.log("reward奖励次数:"+goldEgg.reward.length);
//    	cc.log("reward奖励类型:"+goldEgg.reward[0][0]);
//    	cc.log("reward数量:"+goldEgg.reward[0][1]);
    	var type = null;
    	var num = null;
    	if(goldEgg.itemCount>=10){
//    		eggLayer.showManyRewards(goldEgg);
    		var runningScene = cc.director.getRunningScene();
    		var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
    		var modelLayer = new tyNamespace.ModelLayer(70);
    		modelLayer.setTouchArea(cc.size(1065, 605), cc.p(110, 55));
    		modelLayerCancelable.addChild(modelLayer);
    		runningScene.addChild(modelLayerCancelable, 10);
    		var layer = new gpNamespace.RewardLayer(goldEgg.reward);
    		layer.attr({
    			//左上角坐标
    			x: 0,
    			y: cc.winSize.height,
    		});
    		modelLayer.addChild(layer);
    		tyNamespace.AnimationManager.nodeJumpShow(layer, -cc.winSize.height);
    	}else{
    		type = goldEgg.reward[0][0];
    		num = goldEgg.reward[0][1];
    		eggLayer.scheduleOnce(function(){
    			eggLayer.showRewards(type,num);
    		}, 1);
    	}
    	
    	/*for(var i = 0;i<goldEgg.reward.length;i++){
    		type = goldEgg.reward[i][0];
    		num = goldEgg.reward[i][1];
    		cc.log("type:"+type);
    		eggLayer.scheduleOnce(function(){
    			eggLayer.showRewards(type,num);
    		}, 1);
    		switch (type) {
    		case 1:
    			cc.log("获得金币："+goldEgg.reward[i][1]);
    			break;
    		case 2:
    			cc.log("获得钻石："+goldEgg.reward[i][1]);
    			break;
    		case 3:
    			cc.log("获得兑换券："+goldEgg.reward[i][1]);
    			break;

    		default:
    			break;
    		}
    	}*/
    	
    	/*for (var a = 0; a < goldEgg.reward.length; a++) {
    		cc.log("rewardID:" + goldEgg.reward[a][0]);
    		cc.log("rewardType:" + goldEgg.reward[a][1]);
    	}*/

    	/*gpNamespace.Egg.DIAMOND = goldEgg.diamond;
    	gpNamespace.Egg.CANSAIQUAN = goldEgg.cansaiquan;
    	gpNamespace.Egg.VOUCHER = goldEgg.voucher;
    	gpNamespace.Egg.GOLD = goldEgg.gold;
    	gpNamespace.Egg.RESULT = goldEgg.result;
    	gpNamespace.Egg.ITEMCOUNT = goldEgg.itemCount;
    	gpNamespace.Egg.REWARDS = [];*/
    	/*for (var a = 0; a < gpNamespace.Egg.ITEMCOUNT / 2; a++) {
    		gpNamespace.Egg.REWARDS[a] = [];
    		gpNamespace.Egg.REWARDS[a][0] = goldEgg.rewards[a][0];
    		gpNamespace.Egg.REWARDS[a][1] = goldEgg.rewards[a][1];
    	}*/
    	
    	switch (goldEgg.result) {
    	case 0://成功
    		cc.log("onGoldEgg成功");
//			this.topLayer.removeChildByTag(101);
//			this.topLayer.removeChildByTag(102);
//			this.topLayer.removeChildByTag(103);
    		this.topLayer && this.topLayer.setUserGold(goldEgg.gold);
    		this.topLayer && this.topLayer.setUserDiamond(goldEgg.diamond);
    		this.topLayer && this.topLayer.setUserVoucher(goldEgg.voucher);
    		userInfo.gold = goldEgg.gold;
    		userInfo.diamond = goldEgg.diamond;
    		userInfo.voucher = goldEgg.voucher;
    	break;
    	case 1://没注册用户不能砸金蛋
    		cc.log("没注册用户不能砸金蛋");
    		break;
    	case 2://你今天已经砸过金蛋了
    		cc.log("你今天已经砸过金蛋了");
    		break;
    	case 3://砸金蛋任务已过期
    		cc.log("砸金蛋任务已过期");
    		break;
    	}
    },

    onCanEgg: function (event) {
        cc.log("onCanEgg");

        var canEgg = event.getUserData();
        
//        cc.log("count:" + canEgg.itemCount);
        if(canEgg.itemCount == 0){
        	cc.log("今天砸蛋次数："+canEgg.itemCount);
        	this.eggLayer.setCanEgg();
        }else{
        	cc.log("今天砸蛋次数："+canEgg.itemCount);
        	xinyou.netManager.getRestTime(1);//获得金蛋倒计时
        }

        //var runningScene = cc.director.getRunningScene();
        //var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        //var tyModelLayer = new gpNamespace.TyModelLayer();
        //tyModelLayer.setTouchArea(cc.size(1087, 514), cc.p(95, 67));
        //tyModelLayer1.addChild(tyModelLayer);
        //runningScene.addChild(tyModelLayer1, 10);
        //
        //var tyZajindanLayer = new gpNamespace.TyZajindanLayer(canEgg.itemCount);
        //tyZajindanLayer.attr({
        //    x: 0,
        //    y: cc.winSize.height
        //});
        //tyModelLayer.addChild(tyZajindanLayer);
        //
        //tyZajindanLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));
    },
    //先拿qq礼包
    /*onQQLibao: function (event) {
    	cc.log("onQQLibao");
    	
    	var qqLibao = event.getUserData();
    },*/

    eggCallBackRemove: function (armature, movementType, movementID) {
        if (movementType == ccs.MovementEventType.complete) {
            armature.removeFromParent(true);
        }

        var armature = new ccs.Armature("goldd_001u");
        armature.getAnimation().playWithIndex(0);
        armature.getAnimation().setSpeedScale(1);
        armature.setScale(1);
        armature.setAnchorPoint(0.5, 0.5);
        armature.setPosition(705, 408);
        this.eggLayer.addChild(armature);
        armature.getAnimation().setMovementEventCallFunc(this.egg1CallBackRemove, this);
    },

    egg1CallBackRemove: function (armature, movementType, movementID) {
        if (movementType == ccs.MovementEventType.complete) {
            armature.removeFromParent(true);
        }

        var runningScene = cc.director.getRunningScene();
        var juhua = runningScene.getChildByName(gpNamespace.WAIT);
        juhua && juhua.removeFromParent(true);

        this.eggLayer.getParent().getParent().removeFromParent(true);

        var eggArmatrue = this.qpsLayer.getChildByName("eggArmature");
        if (eggArmatrue) {
            eggArmatrue.removeFromParent(true);
        }
        this.qpsLayer.blackEgg.setVisible(true);
        this.qpsLayer.jindanDlbMenu.setVisible(false);

        xinyou.netManager.getRestTime(1);

        var model = new gpNamespace.TyModelLayer1();
        runningScene.addChild(model, 10);

        //背景
        var back = new cc.Sprite(gpNamespace.zjd.Zjd_showBack);
        back.attr({
            x: 640,
            y: 360
        });
        model.addChild(back);
        back.runAction(cc.repeatForever(cc.rotateBy(4, 360)));

        //蛋壳影子
        var eggShadow = new cc.Sprite(gpNamespace.zjd.Zjd_showShadow);
        eggShadow.attr({
            x: 640,
            y: 220
        });
        model.addChild(eggShadow);

        //蛋壳
        var egg = new cc.Sprite(gpNamespace.zjd.Zjd_showEgg);
        egg.attr({
            x: 640,
            y: 300
        });
        model.addChild(egg);

        //标题
        var title = new cc.Sprite(gpNamespace.zjd.Zjd_showTitle);
        title.attr({
            x: 640,
            y: 550
        });
        model.addChild(title);

        //名字
        if (this.eggName != "") {
            var eggName = new cc.Sprite(this.eggName);
            eggName.attr({
                x: 640,
                y: 490
            });
            model.addChild(eggName);
        }

        //图片
        if (this.eggPic != "") {
            var eggPic = new cc.Sprite(this.eggPic);
            eggPic.attr({
                x: 640,
                y: 360
            });
            model.addChild(eggPic);
        }

        //说明
        if (this.eggInfo != "") {
            var eggInfo = new cc.Sprite(this.eggInfo);
            eggInfo.attr({
                x: 640,
                y: 220
            });
            model.addChild(eggInfo);
        }
    },

    onEggNameList: function (event) {
        cc.log("onEggNameList");

        var nameList = event.getUserData();

        //cc.log("itemCount:" + nameList.itemCount);
        //for (var a = 0; a < nameList.itemCount; a++) {
        //    cc.log("goodIconID:" + nameList.itemLists[a][0]);
        //    cc.log("goodID:" + nameList.itemLists[a][1]);
        //    cc.log("userID:" + nameList.itemLists[a][2]);
        //    cc.log("goodName:" + nameList.itemLists[a][3]);
        //    cc.log("nickName:" + nameList.itemLists[a][4]);
        //}

        this.eggNameLayer.scrollview.clearContainer();

        var itemArray = [];
        for (var a = 0; a < nameList.itemCount; a++) {
            itemArray[a] = new cc.Sprite(gpNamespace.zjd.Zjd_itemBackground);

            //cc.log("nameList.itemLists[a][0]:" + nameList.itemLists[a][0]);

            //图标
            var goodIcon;
            if (nameList.itemLists[a][0] >= 5000 && nameList.itemLists[a][0] < 5062) {
                //实物图标
                var goodIconID = nameList.itemLists[a][0];
                var goodIconName = "#sc_swjp_" + this.getIconName(goodIconID, 4999) + "u.png";
                goodIcon = new cc.Sprite(goodIconName);
                goodIcon.attr({
                    x: 65,
                    y: 8,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(goodIcon, 1);
            }
            if (nameList.itemLists[a][0] == 0) {
                //实物图标
                var goodID = nameList.itemLists[a][1];
                goodIcon = new LoadHead(goodID);
                goodIcon.loadGood();
                goodIcon.attr({
                    x: 65,
                    y: 8,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(goodIcon, 1);
            }
            var x = 90 / goodIcon.getContentSize().width;
            var y = 90 / goodIcon.getContentSize().height;
            goodIcon.setScale(x, y);

            //奖品名字
            var goodName = new cc.LabelTTF(nameList.itemLists[a][3], "Arial", 25);
            goodName.setFontFillColor(cc.color(107, 48, 1, 255));
            goodName.attr({
                x: 325,
                y: 55
            });
            itemArray[a].addChild(goodName, 1);

            //中奖人名字
            var nickName = new cc.LabelTTF(nameList.itemLists[a][4], "Arial", 25);
            nickName.setFontFillColor(cc.color(107, 48, 1, 255));
            nickName.attr({
                x: 575,
                y: 55
            });
            itemArray[a].addChild(nickName, 1);
        }
        this.eggNameLayer.scrollview.setMyContainer(itemArray, 140, 1);
    },

    onPochan: function (event) {
        cc.log("onPochan");

        tyNamespace.removeWaitLayer();

        var pochan = event.getUserData();

        //cc.log("result:" + pochan.result);
        //cc.log("gold:" + pochan.gold);
        //cc.log("pochanCount:" + pochan.pochanCount);

        if (pochan.result == 1) {
            gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.CoinsEffect, false);

            cc.sys.localStorage.setItem(gpNamespace.POCHANCOUNT, pochan.pochanCount);

            var currentGold = userInfo.gold;
            var restGold = parseInt(currentGold) + pochan.gold;
            userInfo.gold = restGold;
            if (this.topLayer) {
                this.topLayer.setUserGold(restGold);
            }

            //金币动画
            //cc.log("破产金币动画");
            var runningScene = cc.director.getRunningScene();
            var runningArmature = new ccs.Armature("coins");
            runningArmature.getAnimation().playWithIndex(0);
            runningArmature.getAnimation().setSpeedScale(1);
            runningArmature.setScale(1);
            runningArmature.setAnchorPoint(0.5, 0.5);
            runningArmature.setPosition(560, 580);
            runningScene.addChild(runningArmature, 10);
            runningArmature.getAnimation().setMovementEventCallFunc(this.callBackRemove, runningScene);
        }
        if (pochan.result == 2) {
            cc.log("已领或不满足资格！");
        }
    },

    callBackRemove: function (armature, movementType, movementID) {
        if (movementType == ccs.MovementEventType.complete) {
            armature.removeFromParent(true);
        }
    },

    onRuchang: function (event) {
        cc.log("onRuchang");

        var ruchang = event.getUserData();

        //cc.log("itemCount:" + ruchang.itemCount);
        //for (var a = 0; a < ruchang.itemCount; a++) {
        //    cc.log("baseScore:" + ruchang.ruchangData[a][0]);//baseScore       底分
        //    cc.log("limitScore:" + ruchang.ruchangData[a][1]);//limitScore      入场限分
        //    cc.log("peopleCount:" + ruchang.ruchangData[a][2]);//peopleCount     场内人数
        //}

        gpNamespace.RuchangInfo.ITEMCOUNT = ruchang.itemCount;
        gpNamespace.RuchangInfo.RUCHANGDATA = [];
        for (var a = 0; a < gpNamespace.RuchangInfo.ITEMCOUNT; a++) {
        	gpNamespace.RuchangInfo.RUCHANGDATA[a] = [];
        	gpNamespace.RuchangInfo.RUCHANGDATA[a][0] = ruchang.ruchangData[a][0];
        	gpNamespace.RuchangInfo.RUCHANGDATA[a][1] = ruchang.ruchangData[a][1];
        	gpNamespace.RuchangInfo.RUCHANGDATA[a][2] = ruchang.ruchangData[a][2];
        }

        if (gpNamespace.ruchangFrom == gpNamespace.RuchangFrom.Cdd)
        	this.jdcLayer.setRuchangInfo();

        tyNamespace.removeWaitLayer();
    },

    //游戏内部聊天信息
    onUserTalk: function (event) {
        cc.log("onUserTalk");

    	var talk = event.getUserData();

    	//cc.log("isSuccess:" + talk.isSuccess);
    	//cc.log("talkIndex:" + talk.talkIndex);
    	//cc.log("talkID:" + talk.talkID);

    	var runningScene = cc.director.getRunningScene();
    	var talkLayer = new cc.Layer();
    	runningScene.addChild(talkLayer, 50);

    	var cddPosition = [cc.p(152, 110), cc.p(616, 325),  cc.p(148, 482)];

    	var cddSpriteName = ["#pdk_yxz_021u.png", "#pdk_yxz_023u.png", "#pdk_yxz_024u.png", "#pdk_yxz_022u.png"];
    	var cddVIPPosition = [cc.p(152, 72), cc.p(923, 280),  cc.p(148, 482)];

    	var cddVIPSpriteName = ["#pdk_yxz_028u.png", "#pdk_yxz_025u.png", "#pdk_yxz_026u.png", "#pdk_yxz_027u.png"];

    	var cddOffset = [cc.p(0, -19), cc.p(0, -19),  cc.p(0, 16)];
    	var cddVIPoffset = [cc.p(25, -5), cc.p(-20, 0),  cc.p(32, -2)];
    	
//    	var cddOffset = [cc.p(220, -19), cc.p(220, -19), cc.p(220, -16), cc.p(220, 16)];
//    	var cddVIPoffset = [cc.p(245, -5), cc.p(-240, 0), cc.p(220, -20), cc.p(252, -2)];

    	var index = talk.talkIndex;
    	
    	var talkID = talk.talkID;
    	cc.log("index>>>>>"+index+"talkID>>>>>>>>>>"+talkID+"roomtype>>>>>>>>>>>>>>"+gpNamespace.roomType);
    	var currentPosition = cc.p(0, 0);
    	var currentSpriteName = "";
    	var currentOffsetVIP = 0;
    	var currentOffset = 0;

    	if (talk.isSuccess) {
    		switch (gpNamespace.roomType) {
    		case 1:
    			if (talkID > 50) {
    				currentPosition = ddzVIPPosition[index];
    				currentSpriteName = ddzVIPSpriteName[index];
    				currentOffsetVIP = ddzVIPoffset[index];
    			}
    			else {
    				currentPosition = ddzPosition[index];
    				currentSpriteName = ddzSpriteName[index];
    				currentOffset = ddzOffset[index];
    			}

    			break;

    		case 0:
    			if (talkID > 50) {
    				currentPosition = mjVIPPosition[index];
    				currentSpriteName = mjVIPSpriteName[index];
    				currentOffsetVIP = mjVIPoffset[index];
    			}
    			else {
    				currentPosition = mjPosition[index];
    				currentSpriteName = mjSpriteName[index];
    				currentOffset = mjOffset[index];
    			}

    			break;

    		case 2:
    			if (talkID > 50) {
    				currentPosition = dzpkVIPPosition[index];
    				currentSpriteName = dzpkVIPSpriteName[index];
    				currentOffsetVIP = dzpkVIPoffset[index];
    			}
    			else {
    				currentPosition = dzpkPosition[index];
    				currentSpriteName = dzpkSpriteName[index];
    				currentOffset = dzpkOffset[index];
    			}

    			break;

    		case 4:
    			if (talkID > 50) {
    				currentPosition = cddVIPPosition[index];
    				currentSpriteName = cddVIPSpriteName[index];
    				currentOffsetVIP = cddVIPoffset[index];
    			}
    			else {
    				currentPosition = cddPosition[index];
    				currentSpriteName = cddSpriteName[index];
    				currentOffset = cddOffset[index];
    			}
    		case 5:
    			if (talkID > 50) {
    				currentPosition = cddVIPPosition[index];
    				currentSpriteName = cddVIPSpriteName[index];
    				currentOffsetVIP = cddVIPoffset[index];
    			}
    			else {
    				currentPosition = cddPosition[index];
    				currentSpriteName = cddSpriteName[index];
    				currentOffset = cddOffset[index];
    			}

    			break;    
    		}

    		cc.log("currentSpriteName:" + currentSpriteName);

    		var sprite = new cc.Sprite(currentSpriteName);
    		sprite.setPosition(currentPosition);
    		sprite.setAnchorPoint(0, 0);
    		talkLayer.addChild(sprite);

    		if (talkID > 50) {
    			var animationIndex = -1;
    			switch (talkID) {
    			case 51:
    				animationIndex = 0;
    				break;

    			case 52:
    				animationIndex = 4;
    				break;

    			case 53:
    				animationIndex = 5;
    				break;

    			case 54:
    				animationIndex = 1;
    				break;

    			case 55:
    				animationIndex = 2;
    				break;

    			case 56:
    				animationIndex = 3;
    				break;
    			}

    			var armature = new ccs.Armature("vip_bq");
    			armature.getAnimation().playWithIndex(animationIndex);
    			armature.getAnimation().setSpeedScale(1);
    			armature.setScale(1);
    			armature.setAnchorPoint(0.5, 0.5);
    			armature.setPosition(sprite.getContentSize().width / 2 + currentOffsetVIP.x, sprite.getContentSize().height / 2 + currentOffsetVIP.y);
    			sprite.addChild(armature);
    		} else {
    			var count = talkID + 12;
    			cc.log(">>>>>>>>>>>talkID"+talkID);
    			var sprite1Name = "#pdk_lt_" + tyNamespace.FullZero(count.toString(), 3) + "u.png";

    			cc.log("sprite1Name" + sprite1Name);
    			var sprite1 = new cc.Sprite(sprite1Name);
    			sprite1.attr({
    				x: sprite.getContentSize().width / 2 + currentOffset.x,
    				y: sprite.getContentSize().height / 2 + currentOffset.y
    			});
    			sprite.addChild(sprite1);
    		}

    		talkLayer.runAction(cc.sequence(cc.fadeOut(1.5), cc.callFunc(function () {
    			talkLayer.removeFromParent(true);
    		})));
    	}
    	else {
    		cc.log("不是VIP");
    	}
    },

    itemCallbackFunction: function (sender) {
        cc.log("使用道具");

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();

        var goodID = data[0];
        var index = data[1];

        if (gpNamespace.roomType == 2 && currentNetManager.isLooker) {
            gpNamespace.showDialog("观看者不能使用桌面道具!");
            return;
        }

        xinyou.netManager.useProp(goodID, index);
    },

    onGameNotice: function (event) {
        cc.log("onGameNotice");

        /*var gameNotice = event.getUserData();

        //cc.log("isReadDdzMission:" + gameNotice.isReadDdzMission);
        //cc.log("isReadSocial:" + gameNotice.isReadSocial);
        //cc.log("isReadMjMission:" + gameNotice.isReadMjMission);
        //cc.log("isReadMail:" + gameNotice.isReadMail);

        if (cc.sys.isObjectValid(this.topLayer)) {
            if (!cc.sys.isObjectValid(this.topLayer.topItem2))
                return;
            if (gameNotice.isReadMail != 0) {
                var item = this.topLayer.topItem2.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
                if (gameNotice.isReadMail > 9)
                    gameNotice.isReadMail = 10;
                var str = gameNotice.isReadMail + 90;
                var spriteName = "#mj_ty_" + str + ".png";
                var mailImg = new cc.Sprite(spriteName);
                mailImg.attr({
                    x: 0,
                    y: 45
                });
                this.topLayer.topItem2.addChild(mailImg);
                mailImg.setName("notice");
                mailImg.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.05, 1.05), cc.scaleTo(0.5, 1, 1))));
            }
            else {
                var item = this.topLayer.topItem2.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
            }
        }

        if (cc.sys.isObjectValid(this.bottomLayer)) {
            if (!cc.sys.isObjectValid(this.bottomLayer.bottomItem2))
                return;
            if (gameNotice.isReadSocial != 0) {
                var item = this.bottomLayer.bottomItem2.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
                if (gameNotice.isReadSocial > 9)
                    gameNotice.isReadSocial = 0;
                var str = gameNotice.isReadSocial + 90;
                var spriteName = "#mj_ty_" + str + ".png";
                var socialImg = new cc.Sprite(spriteName);
                socialImg.attr({
                    x: 10,
                    y: 100
                });
                this.bottomLayer.bottomItem2.addChild(socialImg);
                socialImg.setScale(1.5);
                socialImg.setName("notice");
                socialImg.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.65, 1.65), cc.scaleTo(0.5, 1.5, 1.5))));
            }
            else {
                var item = this.bottomLayer.bottomItem2.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
            }
        }

        if (cc.sys.isObjectValid(this.bottomLayer)) {
            if (!cc.sys.isObjectValid(this.bottomLayer.ddzMissionItem))
                return;
            if (gameNotice.isReadDdzMission != 0) {
                var item = this.bottomLayer.ddzMissionItem.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
                if (gameNotice.isReadDdzMission > 9)
                    gameNotice.isReadDdzMission = 0;
                var str = gameNotice.isReadDdzMission + 90;
                var spriteName = "#mj_ty_" + str + ".png";
                var missionImg1 = new cc.Sprite(spriteName);
                missionImg1.attr({
                    x: 10,
                    y: 100
                });
                this.bottomLayer.ddzMissionItem.addChild(missionImg1);
                missionImg1.setScale(1.5);
                missionImg1.setName("notice");
                missionImg1.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.65, 1.65), cc.scaleTo(0.5, 1.5, 1.5))));
            }
            else {
                var item = this.bottomLayer.ddzMissionItem.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
            }
        }

        if (cc.sys.isObjectValid(this.bottomLayer)) {
            if (!cc.sys.isObjectValid(this.bottomLayer.mjMissionItem))
                return;
            if (gameNotice.isReadMjMission != 0) {
                var item = this.bottomLayer.mjMissionItem.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
                if (gameNotice.isReadMjMission > 9)
                    gameNotice.isReadMjMission = 0;
                var str = gameNotice.isReadMjMission + 90;
                var spriteName = "#mj_ty_" + str + ".png";
                var missionImg2 = new cc.Sprite(spriteName);
                missionImg2.attr({
                    x: 10,
                    y: 100
                });
                this.bottomLayer.mjMissionItem.addChild(missionImg2);
                missionImg2.setScale(1.5);
                missionImg2.setName("notice");
                missionImg2.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.65, 1.65), cc.scaleTo(0.5, 1.5, 1.5))));
            }
            else {
                var item = this.bottomLayer.mjMissionItem.getChildByName("notice");
                if (item != null)
                    item.removeFromParent(true);
            }
        }*/
    },

    onRestTime: function (event) {
        cc.log("onRestTime");

        var restTime = event.getUserData();

	     cc.log("itemType:" + restTime.itemType);
	     cc.log("timeSec:" + restTime.timeSec);

//        var qpsLayer = this.qpsLayer;
//        var mjMiddleLayer = this.mjMiddleLayer;
//        var ddzMiddleLayer = this.ddzMiddleLayer;
        var waitingTime = restTime.timeSec.toString();
        switch (restTime.itemType) {
            case 1:
                if (userInfo.isKickEgg) {
                	this.eggLayer && this.eggLayer.setEggTime(waitingTime);
                }

                break;

            case 2:
                gpNamespace.isBegin = false;
                if (cc.sys.isObjectValid(this.mjMiddleLayer)) {
                    mjMiddleLayer.scheduleOnce(function () {
                        mjMiddleLayer.sprite1.setVisible(true);
                        mjMiddleLayer.sprite2.setVisible(true);
                        mjMiddleLayer.sprite3.setVisible(false);
                        mjMiddleLayer.setRestTime(restTime.timeSec);
                    }, 1);
                }

                if (cc.sys.isObjectValid(this.ddzMiddleLayer)) {
                    ddzMiddleLayer.scheduleOnce(function () {
                        ddzMiddleLayer.sprite22.setVisible(true);
                        ddzMiddleLayer.sprite23.setVisible(true);
                        ddzMiddleLayer.sprite24.setVisible(false);
                        ddzMiddleLayer.setRestTime(restTime.timeSec);
                    }, 1);
                }

                //争霸赛继续判断是否停赛   争霸赛跨星期一时候继续直接执行退出比赛操作
                var runningScene = cc.director.getRunningScene();
                var currentScene = runningScene.getName();
                if (currentScene == "gameScene") {
                    this.quitZhenbasai();
                }

                break;

            case 3:
                gpNamespace.isBegin = true;
                if (cc.sys.isObjectValid(this.mjMiddleLayer)) {
                    mjMiddleLayer.scheduleOnce(function () {
                        mjMiddleLayer.sprite1.setVisible(true);
                        mjMiddleLayer.sprite2.setVisible(false);
                        mjMiddleLayer.sprite3.setVisible(true);
                        mjMiddleLayer.setRestTime(restTime.timeSec);
                    }, 1);
                }

                if (cc.sys.isObjectValid(this.ddzMiddleLayer)) {
                    ddzMiddleLayer.scheduleOnce(function () {
                        ddzMiddleLayer.sprite22.setVisible(true);
                        ddzMiddleLayer.sprite23.setVisible(false);
                        ddzMiddleLayer.sprite24.setVisible(true);
                        ddzMiddleLayer.setRestTime(restTime.timeSec);
                    }, 1);
                }

                //争霸赛继续判断是否停赛
                var runningScene = cc.director.getRunningScene();
                var currentScene = runningScene.getName();
                if (currentScene == "gameScene") {
                    this.continueZhenbasai();
                }

                break;
        }
    },

    quitZhenbasai: function () {
        if (gpNamespace.gameType == gpNamespace.GameType.Mj) {
            var mjNet = gpNamespace.NetManager.getInstance();
            mjNet.removeMyListeners();
            gpNamespace.NetManager.instance = null;
            xinyou.netManager.leaveRoom();

            cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.DzmjScene()));
        }
        if (gpNamespace.gameType == gpNamespace.GameType.Ddz) {
            var ddzNet = ddzNamespace.NetManager.getInstance();
            ddzNet.removeMyListeners();
            ddzNamespace.NetManager.instance = null;
            xinyou.netManager.leaveRoom();

            cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.DdzScene()));
        }
    },

    continueZhenbasai: function () {
        if (gpNamespace.gameType == gpNamespace.GameType.Mj) {
            var gameScene = new gpNamespace.GameScene();
            currentNetManager.initPlayParam();
            gameScene.scheduleOnce(function () {
                xinyou.netManager.sitDown();
            }, 2);

            cc.director.runScene(new cc.TransitionFade(0.5, gameScene), false);
        }
        if (gpNamespace.gameType == gpNamespace.GameType.Ddz) {
            var ddzNet = ddzNamespace.NetManager.getInstance();
            ddzNet.removeMyListeners();
            ddzNamespace.NetManager.instance = null;
            xinyou.netManager.leaveRoom();

            cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.DdzScene()));
        }
    },

    onGameKick: function (event) {
        cc.log("onGameKick");

        var gameKick = event.getUserData();

        //cc.log("result:" + gameKick.result);

        switch (gameKick.result) {
            case 1:
                var runningScene = cc.director.getRunningScene();
                var tyModelLayer = new gpNamespace.TyModelLayer();
                runningScene.addChild(tyModelLayer, 10);

                var pochanLayer = new gpNamespace.FenghaoLayer();
                pochanLayer.attr({
                    x: 0,
                    y: cc.winSize.height
                });
                tyModelLayer.addChild(pochanLayer);

                pochanLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                break;

            case 2:
                var runningScene = cc.director.getRunningScene();
                var tyModelLayer = new gpNamespace.TyModelLayer();
                runningScene.addChild(tyModelLayer, 10);

                var otherUserLayer = new gpNamespace.OtherUserLayer();
                otherUserLayer.attr({
                    x: 0,
                    y: cc.winSize.height
                });
                tyModelLayer.addChild(otherUserLayer);

                otherUserLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

                //删除登陆记录
                cc.sys.localStorage.removeItem(gpNamespace.USER_ID_BYTE);
                cc.sys.localStorage.removeItem(gpNamespace.USER_NAME);
                cc.sys.localStorage.removeItem(gpNamespace.USER_PASSWORD);

                break;
        }
    },

    onGameCheat: function (event) {
        cc.log("onGameCheat");

        var gameCheat = event.getUserData();

        //cc.log("type:" + gameCheat.type);
        //cc.log("result:" + gameCheat.result);

        switch (gameCheat.type) {
            case 0:
            case 1:
            case 2:
            case 3:
//                var runningScene = cc.director.getRunningScene();
//                var jumper = new gpNamespace.TyJumpLayerWithTextRemoved();
//                jumper.setLabelText("反馈成功!");
//                runningScene.addChild(jumper, 10);
                console.log("反馈成功");
                this.helpLayer.setFankuiInfo();
                break;
            case 4:
                var runningScene = cc.director.getRunningScene();
                var jumper = new gpNamespace.TyJumpLayerWithTextRemoved();
                jumper.setLabelText("举报成功!");
                runningScene.addChild(jumper, 10);
                break;
        }
    },

    onGonggao: function (event) {
        cc.log("onGonggao");
        
        var gonggao = event.getUserData();
      this.cddGonggaoLayer.setGonggaoContainer(gonggao);
        
     cc.log("itemType:" + gonggao.itemType);
     cc.log("info:" + gonggao.itemInfo);
     
     if (gonggao.itemType == 1) {
         cc.log("itemCount:" + gonggao.itemCount);
         for (var a = 0; a < gonggao.itemCount; a++) {
             cc.log("noticeIconID:" + gonggao.notices[a][0]);
             cc.log("noticeID:" + gonggao.notices[a][1]);
             cc.log("content:" + gonggao.notices[a][2]);
             cc.log("title:" + gonggao.notices[a][3]);
         }
     }
     if (gonggao.itemType == 2) {
         cc.log("moreContent:" + gonggao.moreContent);
     }

        /*if (gonggao.itemType == 1) {
            if (gonggao.itemInfo == null || gonggao.itemInfo == "") {
                var noInfo = new cc.Sprite(gpNamespace.hd.Hd_noInfo);
                noInfo.attr({
                    x: this.gonggaoLayer.scrollview1.container.getContentSize().width / 2,
                    y: this.gonggaoLayer.scrollview1.container.getContentSize().height / 2
                });
                this.gonggaoLayer.scrollview1.container.addChild(noInfo);
            }
            else {
                var singleHeight = 20;
                var singleLength = 18;

                //内容多少行
                var content = [];
                gpNamespace.TyTalkData = [];
                var strArray = gpNamespace.GetSlicedArray("　　" + gonggao.itemInfo, singleLength);
                for (var a = 0; a < strArray.length; a++) {
                    content.push(strArray[a]);
                }

                var itemArray = [];

                for (var b = 0; b < content.length; b++) {
                    itemArray[b] = new cc.Sprite(gpNamespace.ty.Ty_dot);

                    var item = new cc.LabelTTF(content[b], "Arial", 20);
                    item.setFontFillColor(cc.color(254, 223, 17, 255));
                    item.attr({
                        x: -90,
                        y: -15,
                        anchorX: 0,
                        anchorY: 0
                    });
                    itemArray[b].addChild(item);
                }

                this.gonggaoLayer.scrollview1.setMyContainer(itemArray, 30, 1);
            }

            var itemArray = [];
            for (var a = 0; a < gonggao.itemCount; a++) {
                //背景
                if (a % 2)
                    itemArray[a] = new cc.Sprite(gpNamespace.hd.Hd_itemBackground1);
                else
                    itemArray[a] = new cc.Sprite(gpNamespace.hd.Hd_itemBackground2);

                var goodIcon;
                if (gonggao.notices[a][0] >= 7000 && gonggao.notices[a][0] < 7003) {
                    //实物图标
                    var goodIconID = gonggao.notices[a][0];
                    var goodIconName = "#zjm_icon_" + this.getIconName(goodIconID, 6999) + "u.png";
                    goodIcon = new cc.Sprite(goodIconName);
                    goodIcon.attr({
                        x: 70,
                        y: 65
                    });
                    itemArray[a].addChild(goodIcon, 1);
                }
                if (gonggao.notices[a][0] == 0) {
                    //实物图标
                    var goodID = gonggao.notices[a][1];
                    goodIcon = new LoadHead(goodID);
                    goodIcon.loadGood();
                    goodIcon.attr({
                        x: 70,
                        y: 65
                    });
                    itemArray[a].addChild(goodIcon, 1);
                }

                //title
                var label = new cc.LabelTTF(gonggao.notices[a][3], "Arial", 25);
                label.setFontFillColor(cc.color(81, 41, 27, 255));
                label.attr({
                    x: 125,
                    y: 70,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(label);

                //content
                var label1 = new cc.LabelTTF(gonggao.notices[a][2], "Arial", 20);
                label1.attr({
                    x: 125,
                    y: 30,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[a].addChild(label1);

                //按钮
                var moreItem = new cc.MenuItemImage(gpNamespace.hd.Hd_itemMenu, gpNamespace.hd.Hd_itemMenu, this.moreCallbackFunction, this);
                moreItem.attr({
                    x: 160 / 2,
                    y: 58 / 2
                });
                moreItem.setUserData([gonggao.notices[a][1], gonggao.notices[a][3]]);
                var moreMenu = new gpNamespace.TyMenu(moreItem);
                moreMenu.attr({
                    x: 395,
                    y: 32
                });
                itemArray[a].addChild(moreMenu);
                moreMenu.setTouchArea(this.gonggaoLayer.scrollview2.touchArea);
                moreMenu.setTouchListener();
            }
            this.gonggaoLayer.scrollview2.setMyContainer(itemArray, 135, 1);
        }

        if (gonggao.itemType == 2) {
            var singleHeight = 30;
            var singleLength = 36;

            //内容多少行
            var content = [];
            gpNamespace.TyTalkData = [];
            var strArray = gpNamespace.GetSlicedArray("　　" + gonggao.moreContent, singleLength);
            for (var a = 0; a < strArray.length; a++) {
                content.push(strArray[a]);
            }

            var itemArray = [];

            for (var b = 0; b < content.length; b++) {
                itemArray[b] = new cc.Sprite(gpNamespace.ty.Ty_dot);

                var item = new cc.LabelTTF(content[b], "Arial", 25);
                item.setFontFillColor(cc.color(81, 41, 27, 255));
                item.attr({
                    x: -220,
                    y: -15,
                    anchorX: 0,
                    anchorY: 0
                });
                itemArray[b].addChild(item);
            }

            this.gonggaoMoreLayer.scrollview.setMyContainer(itemArray, 30, 1);
        }*/
    },

    moreCallbackFunction: function (sender) {
        cc.log("活动详情");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        tyNamespace.setMenuEnable(sender);

        var data = sender.getUserData();
        var noticeID = data[0];
        var title = data[1];

        var runningScene = cc.director.getRunningScene();
        var tyModelLayer1 = new gpNamespace.TyModelLayer1();
        var tyModelLayer = new gpNamespace.TyModelLayer();
        tyModelLayer.setTouchArea(cc.size(585, 679), cc.p(348, 20));
        tyModelLayer1.addChild(tyModelLayer);
        runningScene.addChild(tyModelLayer1, 10);

        var tyHdMoreLayer = new gpNamespace.TyHdMoreLayer(noticeID, title);
        tyHdMoreLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        tyModelLayer.addChild(tyHdMoreLayer);

        tyHdMoreLayer.runAction(cc.moveBy(20 / 60, cc.p(0, -cc.winSize.height)).easing(cc.easeBackOut()));

        xinyou.netManager.getGonggao(2, noticeID);
    },

    onGetQQ: function (event) {
        cc.log("onGetQQ");

        var getQQ = event.getUserData();

        //cc.log("content:" + getQQ.content);

        //this.friendLayer.labelScrollview.getContainer().label.setString(getQQ.content);

        var str = getQQ.content;
        if (str != null) {
            var strArray = str.split("|");
            gpNamespace.TyQQData.push(strArray[0] + "|3");
            gpNamespace.TyQQData.push(strArray[1] + "|3");
        }
    },

    onGetWX: function (event) {
        cc.log("onGetWX");

        var getWX = event.getUserData();

        cc.log("result:" + getWX.result);

        if (getWX.result == 1) {
            userInfo.gold = userInfo.gold + 500;
            if (this.topLayer)
                this.topLayer.setUserGold(userInfo.gold);

            //金币动画
            //cc.log("破产金币动画");
            var runningScene = cc.director.getRunningScene();
            var runningArmature = new ccs.Armature("coins");
            runningArmature.getAnimation().playWithIndex(0);
            runningArmature.getAnimation().setSpeedScale(1);
            runningArmature.setScale(1);
            runningArmature.setAnchorPoint(0.5, 0.5);
            runningArmature.setPosition(560, 580);
            runningScene.addChild(runningArmature, 10);
            runningArmature.getAnimation().setMovementEventCallFunc(this.callBackRemove, runningScene);
        }
    },

    onGetVIPDays: function (event) {
        cc.log("onGetVIPDays");

        var getVIPDays = event.getUserData();

        //cc.log("days:" + getVIPDays.days);

        userInfo.vipDays = getVIPDays.days;

        if (getVIPDays.days > 0) {
            userInfo.isVip = true;

            /*if (cc.sys.isObjectValid(this.userInfoLayer)) {
                this.userInfoLayer.vipDaysLabel.setString("(VIP:" + tyNamespace.FullZero(getVIPDays.days, 1000).toString() + "天)");
            }

            if (cc.sys.isObjectValid(this.topLayer)) {
                this.topLayer.vip.setVisible(true);
            }*/
        }
    },

    onHide: function () {
        cc.log("onHide");

        gpNamespace.isBackground = true;

        var outDate = new Date();
        var outTime = outDate.getTime();

        //cc.log("this.lastInTime:" + this.lastInTime);
        //cc.log("this.lastOutTime:" + this.lastOutTime);

        if (this.lastOutTime == null) {
            cc.audioEngine.pauseMusic();

            this.lastOutTime = outTime;
        }

        //var lastTime = (outTime - this.lastOutTime) / 1000;
        //
        //if (lastTime > 3) {
        //    this.lastOutTime = outTime;
        //
        //    cc.audioEngine.pauseMusic();
        //}
    },

    onShow: function () {
        cc.log("onShow");

        gpNamespace.isBackground = false;

        var inDate = new Date();
        var inTime = inDate.getTime();

        //cc.log("this.lastInTime:" + this.lastInTime);
        //cc.log("this.lastOutTime:" + this.lastOutTime);

        var indeTime = 2000;
        if (this.lastInTime != null)
            indeTime = inTime - this.lastInTime;

        if (this.lastOutTime == null || indeTime < 1000)
            return;

        cc.audioEngine.resumeMusic();

        this.lastInTime = inTime;
        var houtaiTime = (this.lastInTime - this.lastOutTime) / 1000;
        this.lastOutTime = null;

        var currentScene = cc.director.getRunningScene();

        if (currentScene.getName() != "gameScene") {
            cc.log("--大厅--");
        } else {
            if (houtaiTime > 10) {
                gpNamespace.Reconnect();
            }
        }
    },
    
});

gpNamespace.TyNetManager.instance = null;

gpNamespace.TyNetManager.getInstance = function () {
    if (gpNamespace.TyNetManager.instance == null)
        gpNamespace.TyNetManager.instance = new gpNamespace.TyNetManager();
    return gpNamespace.TyNetManager.instance;
};